Documentation
¶
Overview ¶
Package smpp implements SMPP protocol v3.4.
It allows easier creation of SMPP clients and servers by providing utilities for PDU and session handling. In order to do any kind of interaction you first need to create an SMPP Session(https://godoc.org/github.com/daominah/smpp#Session). Session is the main carrier of the protocol and enforcer of the specification rules.
Naked session can be created with:
// You must provide already established connection and configuration struct. Sess := smpp.NewSession(conn, conf)
But it's much more convenient to use helpers that would do the binding with the remote SMSC and return you session prepared for sending:
// Bind with remote server by providing config structs. Sess, err := smpp.BindTRx(sessConf, bindConf)
And once you have the session it can be used for sending PDUs to the binded peer.
sm := smpp.SubmitSm{ SourceAddr: "11111111", DestinationAddr: "22222222", ShortMessage: "Hello from SMPP!", } // Session can then be used for sending PDUs. resp, err := Sess.Send(p)
Session that is no longer used must be closed:
Sess.Close()
If you want to handle incoming requests to the session specify SMPPHandler in session configuration when creating new session similarly to HTTPHandler from _net/http_ package:
conf := smpp.SessionConf{ Handler: smpp.HandlerFunc(func(ctx *smpp.Context) { switch ctx.CommandID() { case pdu.UnbindID: ubd, err := ctx.Unbind() if err != nil { t.Errorf(err.Error()) } resp := ubd.Response() if err := ctx.Respond(resp, pdu.StatusOK); err != nil { t.Errorf(err.Error()) } } }), }
Detailed examples for SMPP client and server can be found in the examples dir.
Index ¶
- Constants
- func SendAlertNotification(ctx context.Context, sess *Session, p *pdu.AlertNotification) error
- func SendBindRx(ctx context.Context, sess *Session, p *pdu.BindRx) (*pdu.BindRxResp, error)
- func SendBindRxResp(ctx context.Context, sess *Session, p *pdu.BindRxResp) error
- func SendBindTRx(ctx context.Context, sess *Session, p *pdu.BindTRx) (*pdu.BindTRxResp, error)
- func SendBindTRxResp(ctx context.Context, sess *Session, p *pdu.BindTRxResp) error
- func SendBindTx(ctx context.Context, sess *Session, p *pdu.BindTx) (*pdu.BindTxResp, error)
- func SendBindTxResp(ctx context.Context, sess *Session, p *pdu.BindTxResp) error
- func SendCancelSm(ctx context.Context, sess *Session, p *pdu.CancelSm) (*pdu.CancelSmResp, error)
- func SendCancelSmResp(ctx context.Context, sess *Session, p *pdu.CancelSmResp) error
- func SendDataSm(ctx context.Context, sess *Session, p *pdu.DataSm) (*pdu.DataSmResp, error)
- func SendDataSmResp(ctx context.Context, sess *Session, p *pdu.DataSmResp) error
- func SendDeliverSm(ctx context.Context, sess *Session, p *pdu.DeliverSm) (*pdu.DeliverSmResp, error)
- func SendDeliverSmResp(ctx context.Context, sess *Session, p *pdu.DeliverSmResp) error
- func SendEnquireLink(ctx context.Context, sess *Session, p *pdu.EnquireLink) (*pdu.EnquireLinkResp, error)
- func SendEnquireLinkResp(ctx context.Context, sess *Session, p *pdu.EnquireLinkResp) error
- func SendGenericNack(ctx context.Context, sess *Session, p *pdu.GenericNack) error
- func SendOutbind(ctx context.Context, sess *Session, p *pdu.Outbind) error
- func SendQuerySm(ctx context.Context, sess *Session, p *pdu.QuerySm) (*pdu.QuerySmResp, error)
- func SendQuerySmResp(ctx context.Context, sess *Session, p *pdu.QuerySmResp) error
- func SendReplaceSm(ctx context.Context, sess *Session, p *pdu.ReplaceSm) (*pdu.ReplaceSmResp, error)
- func SendReplaceSmResp(ctx context.Context, sess *Session, p *pdu.ReplaceSmResp) error
- func SendSubmitMulti(ctx context.Context, sess *Session, p *pdu.SubmitMulti) (*pdu.SubmitMultiResp, error)
- func SendSubmitMultiResp(ctx context.Context, sess *Session, p *pdu.SubmitMultiResp) error
- func SendSubmitSm(ctx context.Context, sess *Session, p *pdu.SubmitSm) (*pdu.SubmitSmResp, error)
- func SendSubmitSmResp(ctx context.Context, sess *Session, p *pdu.SubmitSmResp) error
- func SendUnbind(ctx context.Context, sess *Session, p *pdu.Unbind) (*pdu.UnbindResp, error)
- func SendUnbindResp(ctx context.Context, sess *Session, p *pdu.UnbindResp) error
- func Unbind(ctx context.Context, sess *Session) error
- type BindConf
- type Context
- func (ctx *Context) AlertNotification() (*pdu.AlertNotification, error)
- func (ctx *Context) BindRx() (*pdu.BindRx, error)
- func (ctx *Context) BindRxResp() (*pdu.BindRxResp, error)
- func (ctx *Context) BindTRx() (*pdu.BindTRx, error)
- func (ctx *Context) BindTRxResp() (*pdu.BindTRxResp, error)
- func (ctx *Context) BindTx() (*pdu.BindTx, error)
- func (ctx *Context) BindTxResp() (*pdu.BindTxResp, error)
- func (ctx *Context) CancelSm() (*pdu.CancelSm, error)
- func (ctx *Context) CancelSmResp() (*pdu.CancelSmResp, error)
- func (ctx *Context) CloseSession()
- func (ctx *Context) CommandID() pdu.CommandID
- func (ctx *Context) Context() context.Context
- func (ctx *Context) DataSm() (*pdu.DataSm, error)
- func (ctx *Context) DataSmResp() (*pdu.DataSmResp, error)
- func (ctx *Context) DebugReq() string
- func (ctx *Context) DeliverSm() (*pdu.DeliverSm, error)
- func (ctx *Context) DeliverSmResp() (*pdu.DeliverSmResp, error)
- func (ctx *Context) EnquireLink() (*pdu.EnquireLink, error)
- func (ctx *Context) EnquireLinkResp() (*pdu.EnquireLinkResp, error)
- func (ctx *Context) GenericNack() (*pdu.GenericNack, error)
- func (ctx *Context) Outbind() (*pdu.Outbind, error)
- func (ctx *Context) QuerySm() (*pdu.QuerySm, error)
- func (ctx *Context) QuerySmResp() (*pdu.QuerySmResp, error)
- func (ctx *Context) RemoteAddr() string
- func (ctx *Context) ReplaceSm() (*pdu.ReplaceSm, error)
- func (ctx *Context) ReplaceSmResp() (*pdu.ReplaceSmResp, error)
- func (ctx *Context) Respond(resp pdu.PDU, status pdu.Status) error
- func (ctx *Context) SessionID() string
- func (ctx *Context) Status() pdu.Status
- func (ctx *Context) SubmitMulti() (*pdu.SubmitMulti, error)
- func (ctx *Context) SubmitMultiResp() (*pdu.SubmitMultiResp, error)
- func (ctx *Context) SubmitSm() (*pdu.SubmitSm, error)
- func (ctx *Context) SubmitSmResp() (*pdu.SubmitSmResp, error)
- func (ctx *Context) SystemID() string
- func (ctx *Context) Unbind() (*pdu.Unbind, error)
- func (ctx *Context) UnbindResp() (*pdu.UnbindResp, error)
- type DefaultLogger
- type Error
- type Handler
- type HandlerFunc
- type Logger
- type RemoteAddresser
- type Server
- type Session
- type SessionConf
- type SessionState
- type SessionType
- type StatusError
Constants ¶
const ( // Version of the supported SMPP Protocol. Only supporting 3.4 for now. Version = 0x34 // SequenceStart is the starting reference for sequence number. SequenceStart = 0x00000001 // SequenceEnd s sequence number upper boundary. SequenceEnd = 0x7FFFFFFF )
Variables ¶
This section is empty.
Functions ¶
func SendAlertNotification ¶
SendAlertNotification is a helper function for sending AlertNotification PDU.
func SendBindRx ¶
SendBindRx is a helper function for sending BindRx PDU.
func SendBindRxResp ¶
SendBindRxResp is a helper function for sending BindRxResp PDU.
func SendBindTRx ¶
SendBindTRx is a helper function for sending BindTRx PDU.
func SendBindTRxResp ¶
SendBindTRxResp is a helper function for sending BindTRxResp PDU.
func SendBindTx ¶
SendBindTx is a helper function for sending BindTx PDU.
func SendBindTxResp ¶
SendBindTxResp is a helper function for sending BindTxResp PDU.
func SendCancelSm ¶
SendCancelSm is a helper function for sending CancelSm PDU.
func SendCancelSmResp ¶
SendCancelSmResp is a helper function for sending CancelSmResp PDU.
func SendDataSm ¶
SendDataSm is a helper function for sending DataSm PDU.
func SendDataSmResp ¶
SendDataSmResp is a helper function for sending DataSmResp PDU.
func SendDeliverSm ¶
func SendDeliverSm(ctx context.Context, sess *Session, p *pdu.DeliverSm) (*pdu.DeliverSmResp, error)
SendDeliverSm is a helper function for sending DeliverSm PDU.
func SendDeliverSmResp ¶
SendDeliverSmResp is a helper function for sending DeliverSmResp PDU.
func SendEnquireLink ¶
func SendEnquireLink(ctx context.Context, sess *Session, p *pdu.EnquireLink) (*pdu.EnquireLinkResp, error)
SendEnquireLink is a helper function for sending EnquireLink PDU.
func SendEnquireLinkResp ¶
SendEnquireLinkResp is a helper function for sending EnquireLinkResp PDU.
func SendGenericNack ¶
SendGenericNack is a helper function for sending GenericNack PDU.
func SendOutbind ¶
SendOutbind is a helper function for sending Outbind PDU.
func SendQuerySm ¶
SendQuerySm is a helper function for sending QuerySm PDU.
func SendQuerySmResp ¶
SendQuerySmResp is a helper function for sending QuerySmResp PDU.
func SendReplaceSm ¶
func SendReplaceSm(ctx context.Context, sess *Session, p *pdu.ReplaceSm) (*pdu.ReplaceSmResp, error)
SendReplaceSm is a helper function for sending ReplaceSm PDU.
func SendReplaceSmResp ¶
SendReplaceSmResp is a helper function for sending ReplaceSmResp PDU.
func SendSubmitMulti ¶
func SendSubmitMulti(ctx context.Context, sess *Session, p *pdu.SubmitMulti) (*pdu.SubmitMultiResp, error)
SendSubmitMulti is a helper function for sending SubmitMulti PDU.
func SendSubmitMultiResp ¶
SendSubmitMultiResp is a helper function for sending SubmitMultiResp PDU.
func SendSubmitSm ¶
SendSubmitSm is a helper function for sending SubmitSm PDU.
func SendSubmitSmResp ¶
SendSubmitSmResp is a helper function for sending SubmitSmResp PDU.
func SendUnbind ¶
SendUnbind is a helper function for sending Unbind PDU.
func SendUnbindResp ¶
SendUnbindResp is a helper function for sending UnbindResp PDU.
Types ¶
type BindConf ¶
type BindConf struct { // Bind will be attempted to this addr. Addr string // Mandatory fields for binding PDU. SystemID string Password string SystemType string AddrTon int AddrNpi int AddrRange string }
BindConf is the configuration for binding to smpp servers.
type Context ¶
type Context struct { Sess *Session // contains filtered or unexported fields }
Context represents container for SMPP request related information.
func (*Context) AlertNotification ¶
func (ctx *Context) AlertNotification() (*pdu.AlertNotification, error)
AlertNotification returns generic request PDU as pdu.AlertNotification.
func (*Context) BindRxResp ¶
func (ctx *Context) BindRxResp() (*pdu.BindRxResp, error)
BindRxResp returns generic request PDU as pdu.BindRxResp.
func (*Context) BindTRxResp ¶
func (ctx *Context) BindTRxResp() (*pdu.BindTRxResp, error)
BindTRxResp returns generic request PDU as pdu.BindTRxResp.
func (*Context) BindTxResp ¶
func (ctx *Context) BindTxResp() (*pdu.BindTxResp, error)
BindTxResp returns generic request PDU as pdu.BindTxResp.
func (*Context) CancelSmResp ¶
func (ctx *Context) CancelSmResp() (*pdu.CancelSmResp, error)
CancelSmResp returns generic request PDU as pdu.CancelSmResp.
func (*Context) CloseSession ¶
func (ctx *Context) CloseSession()
CloseSession will initiate session shutdown after handler returns.
func (*Context) DataSmResp ¶
func (ctx *Context) DataSmResp() (*pdu.DataSmResp, error)
DataSmResp returns generic request PDU as pdu.DataSmResp.
func (*Context) DeliverSmResp ¶
func (ctx *Context) DeliverSmResp() (*pdu.DeliverSmResp, error)
DeliverSmResp returns generic request PDU as pdu.DeliverSmResp.
func (*Context) EnquireLink ¶
func (ctx *Context) EnquireLink() (*pdu.EnquireLink, error)
EnquireLink returns generic request PDU as pdu.EnquireLink.
func (*Context) EnquireLinkResp ¶
func (ctx *Context) EnquireLinkResp() (*pdu.EnquireLinkResp, error)
EnquireLinkResp returns generic request PDU as pdu.EnquireLinkResp.
func (*Context) GenericNack ¶
func (ctx *Context) GenericNack() (*pdu.GenericNack, error)
GenericNack returns generic request PDU as pdu.GenericNack.
func (*Context) QuerySmResp ¶
func (ctx *Context) QuerySmResp() (*pdu.QuerySmResp, error)
QuerySmResp returns generic request PDU as pdu.QuerySmResp.
func (*Context) RemoteAddr ¶
RemoteAddr returns IP address of the bounded peer.
func (*Context) ReplaceSmResp ¶
func (ctx *Context) ReplaceSmResp() (*pdu.ReplaceSmResp, error)
ReplaceSmResp returns generic request PDU as pdu.ReplaceSmResp.
func (*Context) SessionID ¶
SessionID returns ID of the session that this context is responsible for handling this request.
func (*Context) SubmitMulti ¶
func (ctx *Context) SubmitMulti() (*pdu.SubmitMulti, error)
SubmitMulti returns generic request PDU as pdu.SubmitMulti.
func (*Context) SubmitMultiResp ¶
func (ctx *Context) SubmitMultiResp() (*pdu.SubmitMultiResp, error)
SubmitMultiResp returns generic request PDU as pdu.SubmitMultiResp.
func (*Context) SubmitSmResp ¶
func (ctx *Context) SubmitSmResp() (*pdu.SubmitSmResp, error)
SubmitSmResp returns generic request PDU as pdu.SubmitSmResp.
func (*Context) UnbindResp ¶
func (ctx *Context) UnbindResp() (*pdu.UnbindResp, error)
UnbindResp returns generic request PDU as pdu.UnbindResp.
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger prints logs if smpp.logs flag is set.
func (DefaultLogger) ErrorF ¶
func (dl DefaultLogger) ErrorF(msg string, params ...interface{})
ErrorF implements Logger interface.
func (DefaultLogger) InfoF ¶
func (dl DefaultLogger) InfoF(msg string, params ...interface{})
InfoF implements Logger interface.
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc wraps func into Handler.
func (HandlerFunc) ServeSMPP ¶
func (hc HandlerFunc) ServeSMPP(ctx *Context)
ServeSMPP implements Handler interface.
type Logger ¶
type Logger interface { InfoF(msg string, params ...interface{}) ErrorF(msg string, params ...interface{}) }
Logger provides logging interface for getting info about internals of smpp package.
type RemoteAddresser ¶
RemoteAddresser is an abstraction to keep Session from depending on network connection.
type Server ¶
type Server struct { Addr string SessionConf *SessionConf // contains filtered or unexported fields }
Server implements SMPP SMSC server.
func NewServer ¶
func NewServer(addr string, conf SessionConf) *Server
NewServer creates new SMPP server for managing SMSC sessions. Sessions will use provided SessionConf as template configuration.
func (*Server) ListenAndServe ¶
ListenAndServe starts server listening. Blocking function.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is the engine that coordinates SMPP protocol for bounded peers.
func BindRx ¶
func BindRx(sc SessionConf, bc BindConf) (*Session, error)
BindRx binds receiver session.
func BindTRx ¶
func BindTRx(sc SessionConf, bc BindConf) (*Session, error)
BindTRx binds transreceiver session.
func BindTx ¶
func BindTx(sc SessionConf, bc BindConf) (*Session, error)
BindTx binds transmitter session.
func NewSession ¶
func NewSession(rwc io.ReadWriteCloser, conf SessionConf) *Session
NewSession creates new SMPP session and starts goroutine for listening incoming requests so make sure to call Session.Close() after you are done using it to avoid goroutine leak. Session will take ownership of the ReadWriteCloser and call Close on it during shutdown.
func (*Session) Close ¶
Close implements Closer interface. It MUST be called to dispose session cleanly. It gracefully waits for all handlers to finish execution before returning.
func (*Session) NotifyClosed ¶
func (sess *Session) NotifyClosed() <-chan struct{}
NotifyClosed provides channel that will be closed once session enters closed state.
type SessionConf ¶
type SessionConf struct { Type SessionType SendWinSize int ReqWinSize int WindowTimeout time.Duration SessionState func(sessionID, systemID string, state SessionState) SystemID string ID string Logger Logger Handler Handler Sequencer pdu.Sequencer }
SessionConf structured session configuration.
type SessionState ¶
type SessionState int
SessionState describes session state.
const ( // StateOpen is the initial session state. StateOpen SessionState = iota // StateBinding session has started binding process. // All communication will be blocked until session is bound. StateBinding // StateBoundTx session is bound as transmitter. StateBoundTx // StateBoundRx session is bound as receiver. StateBoundRx // StateBoundTRx session is bound as transceiver. StateBoundTRx // StateUnbinding session has started unbinding process. // Prevents any communication until unbinding is finished. StateUnbinding // StateClosing session is gracefully closing. StateClosing // StateClosed session is closed. StateClosed )
func (SessionState) String ¶
func (i SessionState) String() string
type SessionType ¶
type SessionType int
SessionType defines if session is ESME or SMSC. In other words it defines if the session will behave like a client or like a server.
const ( // ESME type of the session. ESME SessionType = iota // SMSC type of the session. SMSC )
func (SessionType) String ¶
func (i SessionType) String() string
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError implements error interface for SMPP status errors.
func (StatusError) Status ¶
func (se StatusError) Status() pdu.Status
Status returns PDU status code of the error.