Packages
smppex
3.0.4
3.3.0
3.2.4
3.2.3
3.2.2
3.2.1
3.2.0
retired
3.1.0
retired
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.4.0
2.3.3
2.3.2
2.3.1
2.3.0
2.2.9
2.2.8
2.2.7
2.2.6
2.2.5
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.0
2.0.1
2.0.0
1.0.1
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
SMPP 3.4 protocol and framework implemented in Elixir
Current section
Files
Jump to
Current section
Files
lib/smppex/pdu/ton_npi_defaults.ex
defmodule SMPPEX.Pdu.TONNPIDefaults do
@moduledoc """
Module for automatic TON/NPI detection
"""
def ton_npi(address) when is_binary(address) do
address
|> address_type()
|> ton_npi_by_type()
end
@num ~r/\A\+?[[:digit:]]+\z/
@alnum ~r/\A[[:alnum:]]{1,30}\z/
defp address_type(address) do
if Regex.match?(@num, address) do
case String.length(address) do
x when x in 3..8 -> :shortcode
x when x in 9..16 -> :longcode
_ -> :unknown
end
else
if Regex.match?(@alnum, address) do
:alphanumeric
else
:unknown
end
end
end
defp ton_npi_by_type(:shortcode), do: {3, 0}
defp ton_npi_by_type(:longcode), do: {1, 1}
defp ton_npi_by_type(:alphanumeric), do: {5, 0}
defp ton_npi_by_type(:unknown), do: {0, 0}
end