anthill_smpp_ruby 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README +30 -0
  3. data/anthill_smpp_ruby.gemspec +18 -0
  4. data/changelog +43 -0
  5. data/data/dumps/random_command.dump +1 -0
  6. data/data/dumps/smpp_alert_notification.dump +1 -0
  7. data/data/dumps/smpp_bind_receiver.dump +1 -0
  8. data/data/dumps/smpp_bind_receiver_resp.dump +1 -0
  9. data/data/dumps/smpp_bind_transceiver.dump +1 -0
  10. data/data/dumps/smpp_bind_transceiver_1.dump +2 -0
  11. data/data/dumps/smpp_bind_transceiver_resp.dump +1 -0
  12. data/data/dumps/smpp_bind_transmitter.dump +1 -0
  13. data/data/dumps/smpp_bind_transmitter_resp.dump +1 -0
  14. data/data/dumps/smpp_broadcast_sm.dump +1 -0
  15. data/data/dumps/smpp_broadcast_sm_resp.dump +1 -0
  16. data/data/dumps/smpp_cancel_broadcast_sm.dump +1 -0
  17. data/data/dumps/smpp_cancel_broadcast_sm_resp.dump +1 -0
  18. data/data/dumps/smpp_cancel_sm.dump +1 -0
  19. data/data/dumps/smpp_cancel_sm_resp.dump +1 -0
  20. data/data/dumps/smpp_data_sm.dump +1 -0
  21. data/data/dumps/smpp_data_sm_resp.dump +1 -0
  22. data/data/dumps/smpp_deliver_sm.dump +1 -0
  23. data/data/dumps/smpp_deliver_sm_resp.dump +1 -0
  24. data/data/dumps/smpp_enquire_link.dump +1 -0
  25. data/data/dumps/smpp_enquire_link_resp.dump +1 -0
  26. data/data/dumps/smpp_generic_nack.dump +1 -0
  27. data/data/dumps/smpp_outbind.dump +1 -0
  28. data/data/dumps/smpp_query_broadcast_sm.dump +1 -0
  29. data/data/dumps/smpp_query_broadcast_sm_resp.dump +1 -0
  30. data/data/dumps/smpp_query_broadcast_sm_resp_1.dump +1 -0
  31. data/data/dumps/smpp_query_sm.dump +1 -0
  32. data/data/dumps/smpp_query_sm_resp.dump +1 -0
  33. data/data/dumps/smpp_replace_sm.dump +1 -0
  34. data/data/dumps/smpp_replace_sm_resp.dump +1 -0
  35. data/data/dumps/smpp_submit_multi.dump +1 -0
  36. data/data/dumps/smpp_submit_multi_resp.dump +1 -0
  37. data/data/dumps/smpp_submit_sm.dump +1 -0
  38. data/data/dumps/smpp_submit_sm_resp.dump +1 -0
  39. data/data/dumps/smpp_unbind.dump +1 -0
  40. data/data/dumps/smpp_unbind_resp.dump +1 -0
  41. data/data/pdus/random_command.xml +35 -0
  42. data/data/pdus/smpp_alert_notification.xml +14 -0
  43. data/data/pdus/smpp_alert_notification_no_optional.xml +13 -0
  44. data/data/pdus/smpp_bind_receiver.xml +17 -0
  45. data/data/pdus/smpp_bind_receiver_resp.xml +12 -0
  46. data/data/pdus/smpp_bind_receiver_resp_no_optional.xml +11 -0
  47. data/data/pdus/smpp_bind_transceiver.xml +17 -0
  48. data/data/pdus/smpp_bind_transceiver_resp.xml +12 -0
  49. data/data/pdus/smpp_bind_transceiver_resp_no_optional.xml +11 -0
  50. data/data/pdus/smpp_bind_transmitter.xml +17 -0
  51. data/data/pdus/smpp_bind_transmitter_resp.xml +12 -0
  52. data/data/pdus/smpp_bind_transmitter_resp_no_optional.xml +11 -0
  53. data/data/pdus/smpp_broadcast_sm.xml +47 -0
  54. data/data/pdus/smpp_broadcast_sm_no_optional.xml +26 -0
  55. data/data/pdus/smpp_broadcast_sm_resp.xml +14 -0
  56. data/data/pdus/smpp_broadcast_sm_resp_no_optional.xml +8 -0
  57. data/data/pdus/smpp_cancel_broadcast_sm.xml +17 -0
  58. data/data/pdus/smpp_cancel_broadcast_sm_no_optional.xml +15 -0
  59. data/data/pdus/smpp_cancel_broadcast_sm_resp.xml +7 -0
  60. data/data/pdus/smpp_cancel_sm.xml +18 -0
  61. data/data/pdus/smpp_cancel_sm_resp.xml +10 -0
  62. data/data/pdus/smpp_commands.xsd +914 -0
  63. data/data/pdus/smpp_data_sm.xml +58 -0
  64. data/data/pdus/smpp_data_sm_no_optional.xml +17 -0
  65. data/data/pdus/smpp_data_sm_resp.xml +15 -0
  66. data/data/pdus/smpp_data_sm_resp_no_optional.xml +8 -0
  67. data/data/pdus/smpp_deliver_sm.xml +46 -0
  68. data/data/pdus/smpp_deliver_sm_no_optional.xml +25 -0
  69. data/data/pdus/smpp_deliver_sm_resp.xml +14 -0
  70. data/data/pdus/smpp_deliver_sm_resp_no_optional.xml +8 -0
  71. data/data/pdus/smpp_enquire_link.xml +10 -0
  72. data/data/pdus/smpp_enquire_link_resp.xml +10 -0
  73. data/data/pdus/smpp_generic_nack.xml +10 -0
  74. data/data/pdus/smpp_outbind.xml +12 -0
  75. data/data/pdus/smpp_query_broadcast_sm.xml +12 -0
  76. data/data/pdus/smpp_query_broadcast_sm_no_optional.xml +11 -0
  77. data/data/pdus/smpp_query_broadcast_sm_resp.xml +17 -0
  78. data/data/pdus/smpp_query_broadcast_sm_resp_no_optional.xml +15 -0
  79. data/data/pdus/smpp_query_sm.xml +11 -0
  80. data/data/pdus/smpp_query_sm_resp.xml +11 -0
  81. data/data/pdus/smpp_replace_sm.xml +18 -0
  82. data/data/pdus/smpp_replace_sm_no_optional.xml +17 -0
  83. data/data/pdus/smpp_replace_sm_resp.xml +7 -0
  84. data/data/pdus/smpp_submit_multi.xml +73 -0
  85. data/data/pdus/smpp_submit_multi_no_optional.xml +51 -0
  86. data/data/pdus/smpp_submit_multi_resp.xml +35 -0
  87. data/data/pdus/smpp_submit_sm.xml +57 -0
  88. data/data/pdus/smpp_submit_sm_no_optional.xml +28 -0
  89. data/data/pdus/smpp_submit_sm_resp.xml +8 -0
  90. data/data/pdus/smpp_unbind.xml +10 -0
  91. data/data/pdus/smpp_unbind_resp.xml +10 -0
  92. data/examples/dump_viewer.rb +298 -0
  93. data/examples/pdu_composer.rb +1331 -0
  94. data/knownbugs +24 -0
  95. data/lib/anthill_smpp_ruby.rb +83 -0
  96. data/lib/i_smpp_outputter.rb +425 -0
  97. data/lib/pdu/smpp_alert_notification.rb +132 -0
  98. data/lib/pdu/smpp_bind.rb +102 -0
  99. data/lib/pdu/smpp_bind_receiver.rb +29 -0
  100. data/lib/pdu/smpp_bind_receiver_resp.rb +30 -0
  101. data/lib/pdu/smpp_bind_resp.rb +100 -0
  102. data/lib/pdu/smpp_bind_transceiver.rb +29 -0
  103. data/lib/pdu/smpp_bind_transceiver_resp.rb +31 -0
  104. data/lib/pdu/smpp_bind_transmitter.rb +29 -0
  105. data/lib/pdu/smpp_bind_transmitter_resp.rb +30 -0
  106. data/lib/pdu/smpp_broadcast_sm.rb +566 -0
  107. data/lib/pdu/smpp_broadcast_sm_resp.rb +130 -0
  108. data/lib/pdu/smpp_cancel_broadcast_sm.rb +143 -0
  109. data/lib/pdu/smpp_cancel_broadcast_sm_resp.rb +60 -0
  110. data/lib/pdu/smpp_cancel_sm.rb +110 -0
  111. data/lib/pdu/smpp_cancel_sm_resp.rb +60 -0
  112. data/lib/pdu/smpp_data_sm.rb +679 -0
  113. data/lib/pdu/smpp_data_sm_resp.rb +148 -0
  114. data/lib/pdu/smpp_deliver_sm.rb +458 -0
  115. data/lib/pdu/smpp_deliver_sm_resp.rb +137 -0
  116. data/lib/pdu/smpp_enquire_link.rb +59 -0
  117. data/lib/pdu/smpp_enquire_link_resp.rb +61 -0
  118. data/lib/pdu/smpp_generic_nack.rb +61 -0
  119. data/lib/pdu/smpp_outbind.rb +71 -0
  120. data/lib/pdu/smpp_pdu.rb +90 -0
  121. data/lib/pdu/smpp_query_broadcast_sm.rb +120 -0
  122. data/lib/pdu/smpp_query_broadcast_sm_resp.rb +192 -0
  123. data/lib/pdu/smpp_query_sm.rb +92 -0
  124. data/lib/pdu/smpp_query_sm_resp.rb +92 -0
  125. data/lib/pdu/smpp_replace_sm.rb +172 -0
  126. data/lib/pdu/smpp_replace_sm_resp.rb +61 -0
  127. data/lib/pdu/smpp_resp.rb +40 -0
  128. data/lib/pdu/smpp_submit_multi.rb +517 -0
  129. data/lib/pdu/smpp_submit_multi_resp.rb +90 -0
  130. data/lib/pdu/smpp_submit_sm.rb +591 -0
  131. data/lib/pdu/smpp_submit_sm_resp.rb +72 -0
  132. data/lib/pdu/smpp_unbind.rb +60 -0
  133. data/lib/pdu/smpp_unbind_resp.rb +61 -0
  134. data/lib/smpp_constants.rb +917 -0
  135. data/lib/smpp_csv_outputter.rb +1601 -0
  136. data/lib/smpp_datatypes.rb +89 -0
  137. data/lib/smpp_decoder.rb +627 -0
  138. data/lib/smpp_encoder.rb +495 -0
  139. data/lib/smpp_hex_outputter.rb +36 -0
  140. data/lib/smpp_outputter_base.rb +315 -0
  141. data/lib/smpp_structures.rb +98 -0
  142. data/lib/smpp_txt_outputter.rb +1895 -0
  143. data/lib/smpp_validator.rb +373 -0
  144. data/lib/smpp_xml_outputter.rb +34 -0
  145. data/roadmap +18 -0
  146. data/setup.rb +1585 -0
  147. data/test/anthill_smpp_test.rb +29 -0
  148. data/test/smpp_codec_test.rb +30 -0
  149. data/test/smpp_datatypes_test.rb +69 -0
  150. data/test/smpp_outputter_test.rb +1261 -0
  151. data/test/smpp_parsing_test.rb +1758 -0
  152. data/test/smpp_rawdump_test.rb +2095 -0
  153. data/test/smpp_validator_test.rb +441 -0
  154. metadata +206 -0
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright 2007 Majoron.com (developers@majoron.com)
3
+ # Original sources are available at www.majoron.com
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Majoron
19
+ module AntHill
20
+ module SMPP
21
+ # Class describe broadcast area identifier
22
+ class BroadcastAreaIdentifier
23
+ # Constructor.
24
+ def initialize(value = "")
25
+ @value = value
26
+ end
27
+
28
+ def alias?()
29
+ return false if @value.size() == 0
30
+ if RUBY_VERSION >= "1.9.0"
31
+ # Encoding::CompatibilityError: incompatible character encodings: US-ASCII and ASCII-8BIT
32
+ # ASCII-8BIT is a binary data, I am not able to find how to set encoding in constructor
33
+ @value.force_encoding("ASCII-8BIT")
34
+ return value[0].ord == BroadcastAreaFormat::ALIAS
35
+ else
36
+ return value[0] == BroadcastAreaFormat::ALIAS
37
+ end
38
+ end
39
+
40
+ def ellipsoid?()
41
+ return false if @value.size() == 0
42
+ if RUBY_VERSION >= "1.9.0"
43
+ # Encoding::CompatibilityError: incompatible character encodings: US-ASCII and ASCII-8BIT
44
+ # ASCII-8BIT is a binary data, I am not able to find how to set encoding in constructor
45
+ @value.force_encoding("ASCII-8BIT")
46
+ return value[0].ord == BroadcastAreaFormat::ELLIPSOID
47
+ else
48
+ return value[0] == BroadcastAreaFormat::ELLIPSOID
49
+ end
50
+ end
51
+
52
+ def polygon?()
53
+ return false if @value.size() == 0
54
+ if RUBY_VERSION >= "1.9.0"
55
+ # Encoding::CompatibilityError: incompatible character encodings: US-ASCII and ASCII-8BIT
56
+ # ASCII-8BIT is a binary data, I am not able to find how to set encoding in constructor
57
+ @value.force_encoding("ASCII-8BIT")
58
+ return value[0].ord == BroadcastAreaFormat::POLYGON
59
+ else
60
+ return value[0] == BroadcastAreaFormat::POLYGON
61
+ end
62
+ end
63
+
64
+ def broadcast_area_format()
65
+ BroadcastAreaFormat::UNKNOWN if @value.size() == 0
66
+ if RUBY_VERSION >= "1.9.0"
67
+ # Encoding::CompatibilityError: incompatible character encodings: US-ASCII and ASCII-8BIT
68
+ # ASCII-8BIT is a binary data, I am not able to find how to set encoding in constructor
69
+ @value.force_encoding("ASCII-8BIT")
70
+ if value[0].ord == BroadcastAreaFormat::ALIAS ||
71
+ value[0].ord = BroadcastAreaFormat::ELLIPSOID ||
72
+ value[0].ord = BroadcastAreaFormat::POLYGON
73
+ return value[0].ord
74
+ end
75
+ else
76
+ if value[0] == BroadcastAreaFormat::ALIAS ||
77
+ value[0] = BroadcastAreaFormat::ELLIPSOID ||
78
+ value[0] = BroadcastAreaFormat::POLYGON
79
+ return value[0]
80
+ end
81
+ end
82
+ return BroadcastAreaFormat::UNKNOWN
83
+ end
84
+ public
85
+ attr_accessor :value
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,627 @@
1
+ #
2
+ # Copyright 2007 Majoron.com (developers@majoron.com)
3
+ # Original sources are available at www.majoron.com
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Majoron
19
+
20
+ module AntHill
21
+ module SMPP
22
+ class SMPPDecoder < AntHill::BinaryDecoder
23
+
24
+ # Constructor. Insert all SMPP commands to hash. Key is SMPP command identity,
25
+ # and value is SMPP command intanse. Hash is used to get PDU to decode PDU.
26
+ def initialize()
27
+ super()
28
+ end
29
+
30
+ public
31
+ # Method
32
+ def has_tlvs()
33
+ return true if @offset + 1 < decode_command_length()
34
+ return false
35
+ end
36
+
37
+ # Method
38
+ def has_packets()
39
+ return false if @buffer.size() < SMPPOffset::SMPP_HEADER_SIZE
40
+ return false if @buffer.size() < decode_command_length()
41
+ return true
42
+ end
43
+
44
+ # Method
45
+ def get_tlv_code()
46
+ result = 0
47
+ sizeof = 2
48
+ if SMPPOffset::TLV_CODE_POS + sizeof <= @buffer.size()
49
+ shift = @offset + SMPPOffset::TLV_CODE_POS
50
+ result = @buffer[shift..shift+(sizeof-1)].unpack('n').first
51
+ end
52
+ result
53
+ end
54
+
55
+ # Method
56
+ def get_tlv_error()
57
+ tlv_code = get_tlv_code()
58
+ begin_pos = @offset > 2 ? @offset - 2 : 0
59
+ finish_pos = @offset + 2 > @buffer.size() ? @buffer.size() : @offset + 2
60
+ dump = AntHill::ByteBuffer.encode_hex(@buffer[begin_pos .. finish_pos])
61
+ sprintf("Offset: %d, TLVCode: %d, TLVCode 0x%X, Dump[offset-2..@offset+2]: %s",
62
+ @offset, tlv_code, tlv_code, dump)
63
+ end
64
+
65
+
66
+ # Method to get new copy of SMPP command based on byte buffer located at decoder.
67
+ # If byte buffer is large enough then command id extracted and then pdu is returned
68
+ def get_packet()
69
+ case decode_command_id()
70
+ when nil
71
+ return nil
72
+ when CommandId::CM_GENERIC_NACK
73
+ return SMPPGenericNack.new()
74
+ when CommandId::CM_BIND_RECEIVER
75
+ return SMPPBindReceiver.new()
76
+ when CommandId::CM_BIND_RECEIVER_RESP
77
+ return SMPPBindReceiverResp.new()
78
+ when CommandId::CM_BIND_TRANSMITTER
79
+ return SMPPBindTransmitter.new()
80
+ when CommandId::CM_BIND_TRANSMITTER_RESP
81
+ return SMPPBindTransmitterResp.new()
82
+ when CommandId::CM_QUERY_SM
83
+ return SMPPQuerySM.new()
84
+ when CommandId::CM_QUERY_SM_RESP
85
+ return SMPPQuerySMResp.new()
86
+ when CommandId::CM_SUBMIT_SM
87
+ return SMPPSubmitSM.new()
88
+ when CommandId::CM_SUBMIT_SM_RESP
89
+ return SMPPSubmitSMResp.new()
90
+ when CommandId::CM_DELIVER_SM
91
+ return SMPPDeliverSM.new()
92
+ when CommandId::CM_DELIVER_SM_RESP
93
+ return SMPPDeliverSMResp.new()
94
+ when CommandId::CM_UNBIND
95
+ return SMPPUnbind.new()
96
+ when CommandId::CM_UNBIND_RESP
97
+ return SMPPUnbindResp.new()
98
+ when CommandId::CM_REPLACE_SM
99
+ return SMPPReplaceSM.new()
100
+ when CommandId::CM_REPLACE_SM_RESP
101
+ return SMPPReplaceSMResp.new()
102
+ when CommandId::CM_CANCEL_SM
103
+ return SMPPCancelSM.new()
104
+ when CommandId::CM_CANCEL_SM_RESP
105
+ return SMPPCancelSMResp.new()
106
+ when CommandId::CM_BIND_TRANSCEIVER
107
+ return SMPPBindTransceiver.new()
108
+ when CommandId::CM_BIND_TRANSCEIVER_RESP
109
+ return SMPPBindTransceiverResp.new()
110
+ when CommandId::CM_OUTBIND
111
+ return SMPPOutbind.new()
112
+ when CommandId::CM_ENQUIRE_LINK
113
+ return SMPPEnquireLink.new()
114
+ when CommandId::CM_ENQUIRE_LINK_RESP
115
+ return SMPPEnquireLinkResp.new()
116
+ when CommandId::CM_SUBMIT_MULTI
117
+ return SMPPSubmitMulti.new()
118
+ when CommandId::CM_SUBMIT_MULTI_RESP
119
+ return SMPPSubmitMultiResp.new()
120
+ when CommandId::CM_ALERT_NOTIFICATION
121
+ return SMPPAlertNotification.new()
122
+ when CommandId::CM_DATA_SM
123
+ return SMPPDataSM.new()
124
+ when CommandId::CM_DATA_SM_RESP
125
+ return SMPPDataSMResp.new()
126
+ when CommandId::CM_BROADCAST_SM
127
+ return SMPPBroadcastSM.new()
128
+ when CommandId::CM_BROADCAST_SM_RESP
129
+ return SMPPBroadcastSMResp.new()
130
+ when CommandId::CM_QUERY_BROADCAST_SM
131
+ return SMPPQueryBroadcastSM.new()
132
+ when CommandId::CM_QUERY_BROADCAST_SM_RESP
133
+ return SMPPQueryBroadcastSMResp.new()
134
+ when CommandId::CM_CANCEL_BROADCAST_SM
135
+ return SMPPCancelBroadcastSM.new()
136
+ when CommandId::CM_CANCEL_BROADCAST_SM_RESP
137
+ return SMPPCancelBroadcastSMResp.new()
138
+ else
139
+ return nil
140
+ end
141
+ end
142
+
143
+ # Method
144
+ def decode_packet()
145
+ raise "not implemented yet !!!"
146
+ end
147
+
148
+
149
+ # SMPP header decoder
150
+ def decode_header()
151
+ header = AntHill::SMPP::Header.new()
152
+ header.command_length = decode_unsigned32()
153
+ header.command_id = decode_unsigned32(header.command_length)
154
+ header.command_status = decode_unsigned32(header.command_length)
155
+ header.sequence_number = decode_unsigned32(header.command_length)
156
+ header
157
+ end
158
+
159
+ # Mandatory SMPP fields decoder
160
+ def decode_system_id(limit)
161
+ decode_cstring_max(SMPPMaxLen::SYSTEM_ID_MAX_LEN, limit)
162
+ end
163
+
164
+ def decode_password(limit)
165
+ decode_cstring_max(SMPPMaxLen::PASSWORD_MAX_LEN, limit)
166
+ end
167
+
168
+ def decode_system_type(limit)
169
+ decode_cstring_max(SMPPMaxLen::SYSTEM_TYPE_MAX_LEN, limit)
170
+ end
171
+
172
+ def decode_interface_version(limit)
173
+ decode_uchar(limit)
174
+ end
175
+
176
+ def decode_addr_ton(limit)
177
+ decode_uchar(limit)
178
+ end
179
+
180
+ def decode_addr_npi(limit)
181
+ decode_uchar(limit)
182
+ end
183
+
184
+ def decode_address_range(limit)
185
+ decode_cstring_max(SMPPMaxLen::ADDRESS_RANGE_MAX_LEN, limit)
186
+ end
187
+
188
+ def decode_service_type(limit)
189
+ decode_cstring_max(SMPPMaxLen::SERVICE_TYPE_MAX_LEN, limit)
190
+ end
191
+
192
+ def decode_source_addr_ton(limit)
193
+ decode_uchar(limit)
194
+ end
195
+
196
+ def decode_source_addr_npi(limit)
197
+ decode_uchar(limit)
198
+ end
199
+
200
+ def decode_source_addr21(limit)
201
+ decode_cstring_max(SMPPMaxLen::SOURCE_ADDR_MAX_LEN_21, limit)
202
+ end
203
+
204
+ def decode_source_addr65(limit)
205
+ decode_cstring_max(SMPPMaxLen::SOURCE_ADDR_MAX_LEN_65, limit)
206
+ end
207
+
208
+ def decode_dest_addr_ton(limit)
209
+ decode_uchar(limit)
210
+ end
211
+
212
+ def decode_dest_addr_npi(limit)
213
+ decode_uchar(limit)
214
+ end
215
+
216
+ def decode_dest_addr21(limit)
217
+ decode_cstring_max(SMPPMaxLen::DESTINATION_ADDR_MAX_LEN_21, limit)
218
+ end
219
+
220
+ def decode_dest_addr65(limit)
221
+ decode_cstring_max(SMPPMaxLen::DESTINATION_ADDR_MAX_LEN_65, limit)
222
+ end
223
+
224
+ def decode_esm_class(limit)
225
+ decode_uchar(limit)
226
+ end
227
+
228
+ def decode_protocol_id(limit)
229
+ decode_uchar(limit)
230
+ end
231
+
232
+ def decode_priority_flag(limit)
233
+ decode_uchar(limit)
234
+ end
235
+
236
+ def decode_schedule_delivery_time(limit)
237
+ decode_cstring_max(SMPPMaxLen::SMPP_DATETIME_MAX_LEN, limit)
238
+ end
239
+
240
+ def decode_validity_period(limit)
241
+ decode_cstring_max(SMPPMaxLen::SMPP_DATETIME_MAX_LEN, limit)
242
+ end
243
+
244
+ def decode_registered_delivery(limit)
245
+ decode_uchar(limit)
246
+ end
247
+
248
+ def decode_replace_if_present_flag(limit)
249
+ decode_uchar(limit)
250
+ end
251
+
252
+ def decode_data_coding(limit)
253
+ decode_uchar(limit)
254
+ end
255
+
256
+ def decode_sm_default_msg_id(limit)
257
+ decode_uchar(limit)
258
+ end
259
+
260
+ def decode_sm_length(limit)
261
+ decode_uchar(limit)
262
+ end
263
+
264
+ def decode_short_message(sm_length, limit)
265
+ decode_binary(sm_length, limit)
266
+ end
267
+
268
+ def decode_message_id(limit)
269
+ decode_cstring_max(SMPPMaxLen::MESSAGE_ID_MAX_LEN, limit)
270
+ end
271
+
272
+ def decode_esme_addr_ton(limit)
273
+ decode_uchar(limit)
274
+ end
275
+
276
+ def decode_esme_addr_npi(limit)
277
+ decode_uchar(limit)
278
+ end
279
+
280
+ def decode_esme_addr(limit)
281
+ decode_cstring_max(SMPPMaxLen::ESME_ADDR_MAX_LEN, limit)
282
+ end
283
+
284
+ def decode_number_of_dest(limit)
285
+ decode_uchar(limit)
286
+ end
287
+
288
+ def decode_dest_addresses(number_of_dests, limit)
289
+ result = []
290
+ 0.upto(number_of_dests - 1) do |i|
291
+ dest_address = DestAddress.new()
292
+ dest_address.dest_flag = decode_uchar(limit)
293
+ case dest_address.dest_flag
294
+ when DestFlag::SME_ADDRESS
295
+ ton = decode_uchar(limit)
296
+ npi = decode_uchar(limit)
297
+ adr = decode_cstring_max(SMPPMaxLen::DESTINATION_ADDR_MAX_LEN_21,limit)
298
+ dest_address.address = SMEAddress.new(ton, npi, adr)
299
+ when DestFlag::DISTR_LIST_NAME
300
+ dest_address.distr_list_name = decode_cstring_max(SMPPMaxLen::DL_NAME_MAX_LEN, limit)
301
+ else
302
+ # Report about error
303
+ raise spritnf(CodecErrors::DECODER_INV_DSTFLAG, @offset, dest_address.dest_flag)
304
+ end
305
+ result << dest_address
306
+ end
307
+ result
308
+ end
309
+
310
+ def decode_no_unsuccess(limit)
311
+ decode_uchar(limit)
312
+ end
313
+
314
+ def decode_unsuccess_smes(no_unsuccess, limit)
315
+ result = []
316
+ 0.upto(no_unsuccess - 1) do |i|
317
+ ton = decode_uchar(limit)
318
+ npi = decode_uchar(limit)
319
+ adr = decode_cstring_max(SMPPMaxLen::DESTINATION_ADDR_MAX_LEN_21,limit)
320
+ err = decode_unsigned32(limit)
321
+ result << UnsuccessSME.new(SMEAddress.new(ton, npi, adr), err)
322
+ end
323
+ result
324
+ end
325
+
326
+ def decode_final_date(limit)
327
+ decode_cstring_max(SMPPMaxLen::SMPP_DATETIME_MAX_LEN, limit)
328
+ end
329
+
330
+ def decode_error_code(limit)
331
+ decode_uchar(limit)
332
+ end
333
+
334
+ def decode_message_state(limit)
335
+ decode_uchar(limit)
336
+ end
337
+
338
+ def decode_broadcast_area_identifier(limit)
339
+ data, len = decode_binary_tlv(limit)
340
+ return BroadcastAreaIdentifier.new(data), len
341
+ end
342
+
343
+ def decode_broadcast_rep_num(limit)
344
+ decode_uint16_tlv(limit)
345
+ end
346
+
347
+ def decode_broadcast_frequency_interval(limit)
348
+ decode_binary_tlv(limit)
349
+ end
350
+
351
+ def decode_broadcast_area_success(limit)
352
+ decode_uchar_tlv(limit)
353
+ end
354
+
355
+ # Optional (TLV) SMPP fields decoder
356
+ def decode_sc_interface_version(limit)
357
+ decode_uchar_tlv(limit)
358
+ end
359
+
360
+ def decode_ms_availability_status(limit)
361
+ decode_uchar_tlv(limit)
362
+ end
363
+
364
+ def decode_alert_on_msg_delivery(limit)
365
+ decode_uchar_tlv(limit)
366
+ end
367
+
368
+ def decode_broadcast_channel_indicator(limit)
369
+ decode_uchar_tlv(limit)
370
+ end
371
+
372
+ def decode_broadcast_content_type_info(limit)
373
+ decode_binary_tlv(limit)
374
+ end
375
+
376
+ def decode_broadcast_message_class(limit)
377
+ decode_uchar_tlv(limit)
378
+ end
379
+
380
+ def decode_broadcast_service_group(limit)
381
+ decode_binary_tlv(limit)
382
+ end
383
+
384
+ def decode_callback_num(limit)
385
+ decode_binary_tlv(limit)
386
+ end
387
+
388
+ def decode_callback_num_atag(limit)
389
+ decode_binary_tlv(limit)
390
+ end
391
+
392
+ def decode_callback_num_pres_ind(limit)
393
+ decode_uchar_tlv(limit)
394
+ end
395
+
396
+ def decode_dest_addr_subunit(limit)
397
+ decode_uchar_tlv(limit)
398
+ end
399
+
400
+ def decode_dest_subaddress(limit)
401
+ decode_binary_tlv(limit)
402
+ end
403
+
404
+ def decode_display_time(limit)
405
+ decode_uchar_tlv(limit)
406
+ end
407
+
408
+ def decode_language_indicator(limit)
409
+ decode_uchar_tlv(limit)
410
+ end
411
+
412
+ def decode_message_payload(limit)
413
+ decode_binary_tlv(limit)
414
+ end
415
+
416
+ def decode_ms_validity(limit)
417
+ decode_uchar_tlv(limit)
418
+ end
419
+
420
+ def decode_payload_type(limit)
421
+ decode_uchar_tlv(limit)
422
+ end
423
+
424
+ def decode_privacy_indicator(limit)
425
+ decode_uchar_tlv(limit)
426
+ end
427
+
428
+ def decode_sms_signal(limit)
429
+ decode_uint16_tlv(limit)
430
+ end
431
+
432
+ def decode_source_addr_subunit(limit)
433
+ decode_uchar_tlv(limit)
434
+ end
435
+
436
+ def decode_source_port(limit)
437
+ decode_uint16_tlv(limit)
438
+ end
439
+
440
+ def decode_source_subaddress(limit)
441
+ decode_binary_tlv(limit)
442
+ end
443
+
444
+ def decode_user_message_reference(limit)
445
+ decode_uint16_tlv(limit)
446
+ end
447
+
448
+ def decode_broadcast_error_status(limit)
449
+ decode_uint32_tlv(limit)
450
+ end
451
+
452
+ def decode_failed_broadcast_area_identifier(limit)
453
+ data, len = decode_binary_tlv(limit)
454
+ return BroadcastAreaIdentifier.new(data), len
455
+ end
456
+
457
+ def decode_broadcast_content_type(limit)
458
+ decode_binary_tlv(limit)
459
+ end
460
+
461
+ def decode_source_network_type(limit)
462
+ decode_uchar_tlv(limit)
463
+ end
464
+
465
+ def decode_source_bearer_type(limit)
466
+ decode_uchar_tlv(limit)
467
+ end
468
+
469
+ def decode_source_telematics_id(limit)
470
+ decode_uchar_tlv(limit)
471
+ end
472
+
473
+ def decode_destination_port(limit)
474
+ decode_uint16_tlv(limit)
475
+ end
476
+
477
+ def decode_dest_network_type(limit)
478
+ decode_uchar_tlv(limit)
479
+ end
480
+
481
+ def decode_dest_bearer_type(limit)
482
+ decode_uchar_tlv(limit)
483
+ end
484
+
485
+ def decode_dest_telematics_id(limit)
486
+ decode_uchar_tlv(limit)
487
+ end
488
+
489
+ def decode_sar_msg_ref_num(limit)
490
+ decode_uint16_tlv(limit)
491
+ end
492
+
493
+ def decode_sar_total_segments(limit)
494
+ decode_uchar_tlv(limit)
495
+ end
496
+
497
+ def decode_sar_segment_seqnum(limit)
498
+ decode_uchar_tlv(limit)
499
+ end
500
+
501
+ def decode_more_messages_to_send(limit)
502
+ decode_uchar_tlv(limit)
503
+ end
504
+
505
+ def decode_qos_time_to_live(limit)
506
+ decode_uint32_tlv(limit)
507
+ end
508
+
509
+ def decode_set_dpf(limit)
510
+ decode_uchar_tlv(limit)
511
+ end
512
+
513
+ def decode_receipted_message_id(limit)
514
+ decode_cstring_tlv(limit)
515
+ end
516
+
517
+ def decode_message_state_tlv(limit)
518
+ decode_uchar_tlv(limit)
519
+ end
520
+
521
+ def decode_network_error_code(limit)
522
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT)
523
+ len = decode_unsigned16(limit)
524
+ network = decode_uchar(limit)
525
+ error = decode_unsigned16(limit)
526
+ return NetworkErrorCode.new(network, error), len
527
+ end
528
+
529
+ def decode_ms_msg_wait_facilities(limit)
530
+ decode_uchar_tlv(limit)
531
+ end
532
+
533
+ def decode_number_of_messages(limit)
534
+ decode_uchar_tlv(limit)
535
+ end
536
+
537
+ def decode_its_reply_type(limit)
538
+ decode_uchar_tlv(limit)
539
+ end
540
+
541
+ def decode_its_session_info(limit)
542
+ decode_uint16_tlv(limit)
543
+ end
544
+
545
+ def decode_user_response_code(limit)
546
+ decode_uchar_tlv(limit)
547
+ end
548
+
549
+ def decode_delivery_failure_reason(limit)
550
+ decode_uchar_tlv(limit)
551
+ end
552
+
553
+ def decode_additional_status_info_text(limit)
554
+ decode_binary_tlv(limit)
555
+ end
556
+
557
+ def decode_dpf_result(limit)
558
+ decode_uchar_tlv(limit)
559
+ end
560
+
561
+ def decode_broadcast_end_time(limit)
562
+ decode_cstring_tlv(limit)
563
+ end
564
+
565
+ def decode_ussd_service_op(limit)
566
+ decode_uchar_tlv(limit)
567
+ end
568
+
569
+ private
570
+ # Method to decoder command id based on byte buffer located at decoder.
571
+ def decode_command_id()
572
+ sizeof = 4
573
+ shift = SMPPOffset::COMMAND_ID_POS
574
+ if shift + sizeof <= @buffer.size()
575
+ return @buffer[shift.. shift + (sizeof-1)].unpack('N').first
576
+ end
577
+ end
578
+
579
+ # Method to decoder command id based on byte buffer located at decoder.
580
+ def decode_command_length()
581
+ sizeof = 4
582
+ shift = SMPPOffset::COMMAND_LENGTH_POS
583
+ if shift + sizeof <= @buffer.size()
584
+ return @buffer[shift.. shift + (sizeof-1)].unpack('N').first
585
+ end
586
+ end
587
+
588
+ # Auxiliary methods to decode tlv
589
+ def decode_uchar_tlv(limit)
590
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT, limit)
591
+ len = decode_unsigned16(limit)
592
+ val = decode_uchar(limit)
593
+ return val, len
594
+ end
595
+
596
+ def decode_uint16_tlv(limit)
597
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT, limit)
598
+ len = decode_unsigned16(limit)
599
+ val = decode_unsigned16(limit)
600
+ return val, len
601
+ end
602
+
603
+ def decode_uint32_tlv(limit)
604
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT, limit)
605
+ len = decode_unsigned16(limit)
606
+ val = decode_unsigned32(limit)
607
+ return val, len
608
+ end
609
+
610
+ def decode_cstring_tlv(limit)
611
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT, limit)
612
+ len = decode_unsigned16(limit)
613
+ val = decode_cstring_max(len, limit)
614
+ return val, len
615
+ end
616
+
617
+ def decode_binary_tlv(limit)
618
+ skip_n_bytes(SMPPOffset::TLV_TAG_LENGHT, limit)
619
+ len = decode_unsigned16(limit)
620
+ val = decode_binary(len, limit)
621
+ return val, len
622
+ end
623
+ end
624
+
625
+ end
626
+ end
627
+ end