diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index fcf568fcf99b5cf52f3fc0c1077ebe765754eb64..2dac5b1193df9ae460b6a6deed68ecb890603fa8 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -360,10 +360,15 @@ SIPVoIPLink::refuse (const CallID& id) bool SIPVoIPLink::carryingDTMFdigits(const CallID& id, char code UNUSED) { - SIPCall* call = getSIPCall(id); - if (call==0) { _debug("Call doesn't exist\n"); return false; } + int duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH); + const int body_len = 1000; + char *dtmf_body = new char[body_len]; + + snprintf(dtmf_body, body_len - 1, "Signal=%c\r\nDuration=%d\r\n", code, duration); + + return Manager::instance().getUserAgent()->carryingDTMFdigits(call, dtmf_body); + - Manager::instance().getUserAgent()->carryingDTMFdigits(call); //int duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH); // TODO Add DTMF with pjsip - INFO method diff --git a/src/useragent.cpp b/src/useragent.cpp index b703186c540d26eed3ab64f48a127be4016889d3..6625be84318ff3bb792acc470ae4502ce64331cd 100644 --- a/src/useragent.cpp +++ b/src/useragent.cpp @@ -1188,9 +1188,42 @@ bool UserAgent::refuse(SIPCall* call) return true; } -bool UserAgent::carryingDTMFdigits(SIPCall* call) + +bool UserAgent::carryingDTMFdigits(SIPCall* call, char *msgBody) { - return true; + pj_status_t status; + pjsip_method method; + pj_str_t methodName; + pjsip_tx_data *tdata; + pj_str_t from, to, contact, body; + + AccountID accId = Manager::instance().getAccountFromCall(call->getCallId()); + SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(accId)); + + pj_strdup2(_pool, &methodName, "INFO"); + std::string fromStr = "sip:" + account->getUserName() + "@" + account->getServer(); + pj_strdup2(_pool, &from, fromStr.data()); + std::string toStr = "sip:" + call->getPeerNumber(); + pj_strdup2(_pool, &to, toStr.data()); + pj_strdup2(_pool, &contact, account->getContact().data()); + pj_strdup2(_pool, &body, msgBody); + pjsip_method_init_np(&method, &methodName); + + + status = pjsip_endpt_create_request(_endpt, &method, + &to, &from, &to, &contact, NULL, -1, &body, &tdata); + if(status != PJ_SUCCESS) { + _debug("UserAgent: Can not create DTMF message!\n"); + return false; + + } + + status = pjsip_endpt_send_request(_endpt, tdata, -1, NULL, NULL); + if(status != PJ_SUCCESS) { + _debug("UserAgent: Can not send DTMF message!\n"); + return false; + } + return true; } bool UserAgent::transfer(SIPCall *call, const std::string& to) diff --git a/src/useragent.h b/src/useragent.h index a1bb0b02cb6a8b8d92b1d215f9ccd02239b51323..6e99397ffa5baa430e6ea56c71c0f6a12905f9c1 100644 --- a/src/useragent.h +++ b/src/useragent.h @@ -134,8 +134,8 @@ public: void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata); bool makeOutgoingCall(const std::string& to, SIPCall* call, const AccountID& id); - - bool carryingDTMFdigits(SIPCall* call); + + bool carryingDTMFdigits(SIPCall* call, char *msgBody); pj_pool_t *getAppPool() {return _pool;} static pj_bool_t mod_on_rx_request(pjsip_rx_data *rdata);