-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New OnAllPDU seeting that lets users choose to handle all PDUs from S…
…MSC (#110) As propose in #96 and in #107 What: This feature allows the ESME to control PDU response by using a new setting that will handle all PDU. This proposed feature does not interfere with current user behaviour. Why: Some ESME need to validate incoming PDUs, like DeliverSm and DataSM, before returning a response. How: - new `OnAllPDU` setting that lets users choose how to handle PDUs from SMSC - If the user sets new setting, it will overide `OnPDU` - Respond function added to Receivable and Transceivable, to allow Respond/Submit for the response Warning: This setting, if set, overrides `OnPDU` and bypass all auto response feature, Enquirelink and Unbind request must be handled by user. Added a new example called `transcceiver_with_manual_response` to see how it can be used, moved old example in `transceiver_with_auto_response` .
- Loading branch information
1 parent
d095b83
commit 151b333
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"sync" | ||
"time" | ||
|
||
"github.com/linxGnu/gosmpp" | ||
"github.com/linxGnu/gosmpp/data" | ||
"github.com/linxGnu/gosmpp/pdu" | ||
) | ||
|
||
func main() { | ||
var wg sync.WaitGroup | ||
|
||
wg.Add(1) | ||
go sendingAndReceiveSMS(&wg) | ||
|
||
wg.Wait() | ||
} | ||
|
||
func sendingAndReceiveSMS(wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
|
||
auth := gosmpp.Auth{ | ||
SMSC: "localhost:2775", | ||
SystemID: "169994", | ||
Password: "EDXPJU", | ||
SystemType: "", | ||
} | ||
|
||
sendResponse := make(chan pdu.PDU) | ||
defer close(sendResponse) | ||
trans, err := gosmpp.NewSession( | ||
gosmpp.TRXConnector(gosmpp.NonTLSDialer, auth), | ||
gosmpp.Settings{ | ||
EnquireLink: 5 * time.Second, | ||
|
||
ReadTimeout: 10 * time.Second, | ||
|
||
OnSubmitError: func(_ pdu.PDU, err error) { | ||
log.Fatal("SubmitPDU error:", err) | ||
}, | ||
|
||
OnReceivingError: func(err error) { | ||
fmt.Println("Receiving PDU/Network error:", err) | ||
}, | ||
|
||
OnRebindingError: func(err error) { | ||
fmt.Println("Rebinding but error:", err) | ||
}, | ||
|
||
OnAllPDU: handlePDU(), | ||
|
||
OnClosed: func(state gosmpp.State) { | ||
fmt.Println(state) | ||
}, | ||
}, 5*time.Second) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func() { | ||
_ = trans.Close() | ||
}() | ||
|
||
// sending SMS(s) | ||
for i := 0; i < 30; i++ { | ||
if err = trans.Transceiver().Submit(newSubmitSM()); err != nil { | ||
fmt.Println(err) | ||
} | ||
time.Sleep(time.Second) | ||
} | ||
|
||
} | ||
|
||
func handlePDU() func(pdu.PDU) pdu.PDU { | ||
return func(p pdu.PDU) pdu.PDU { | ||
switch pd := p.(type) { | ||
case *pdu.Unbind: | ||
fmt.Println("Unbind Received") | ||
return pd.GetResponse() | ||
|
||
case *pdu.UnbindResp: | ||
fmt.Println("UnbindResp Received") | ||
|
||
case *pdu.SubmitSMResp: | ||
fmt.Println("SubmitSMResp Received") | ||
|
||
case *pdu.GenericNack: | ||
fmt.Println("GenericNack Received") | ||
|
||
case *pdu.EnquireLinkResp: | ||
fmt.Println("EnquireLinkResp Received") | ||
|
||
case *pdu.EnquireLink: | ||
fmt.Println("EnquireLink Received") | ||
return pd.GetResponse() | ||
|
||
case *pdu.DataSM: | ||
fmt.Println("DataSM receiver") | ||
return pd.GetResponse() | ||
|
||
case *pdu.DeliverSM: | ||
fmt.Println("DeliverSM receiver") | ||
return pd.GetResponse() | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func newSubmitSM() *pdu.SubmitSM { | ||
// build up submitSM | ||
srcAddr := pdu.NewAddress() | ||
srcAddr.SetTon(5) | ||
srcAddr.SetNpi(0) | ||
_ = srcAddr.SetAddress("00" + "522241") | ||
|
||
destAddr := pdu.NewAddress() | ||
destAddr.SetTon(1) | ||
destAddr.SetNpi(1) | ||
_ = destAddr.SetAddress("99" + "522241") | ||
|
||
submitSM := pdu.NewSubmitSM().(*pdu.SubmitSM) | ||
submitSM.SourceAddr = srcAddr | ||
submitSM.DestAddr = destAddr | ||
_ = submitSM.Message.SetMessageWithEncoding("Đừng buồn thế dù ngoài kia vẫn mưa nghiễng rợi tý tỵ", data.UCS2) | ||
submitSM.ProtocolID = 0 | ||
submitSM.RegisteredDelivery = 1 | ||
submitSM.ReplaceIfPresentFlag = 0 | ||
submitSM.EsmClass = 0 | ||
|
||
return submitSM | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters