From 62e71dfa694a20d6834063926be5ce80244c67ef Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 5 Oct 2007 09:12:26 +0000 Subject: Ticket #391: Added framework to send and receive arbitrary requests within call in PJSUA-LIB, with samples to send/receive DTMF with INFO in pjsua application git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1477 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/pjsua_app.c | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) (limited to 'pjsip-apps/src/pjsua/pjsua_app.c') diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index ceb97e3d..4b2b001b 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -1595,6 +1595,72 @@ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, } +/* + * Handler when a transaction within a call has changed state. + */ +static void on_call_tsx_state(pjsua_call_id call_id, + pjsip_transaction *tsx, + pjsip_event *e) +{ + const pjsip_method info_method = + { + PJSIP_OTHER_METHOD, + { "INFO", 4 } + }; + + if (pjsip_method_cmp(&tsx->method, &info_method)==0) { + /* + * Handle INFO method. + */ + if (tsx->role == PJSIP_ROLE_UAC && + (tsx->state == PJSIP_TSX_STATE_COMPLETED || + tsx->state == PJSIP_TSX_STATE_TERMINATED && + e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED)) + { + /* Status of outgoing INFO request */ + if (tsx->status_code >= 200 && tsx->status_code < 300) { + PJ_LOG(4,(THIS_FILE, + "Call %d: DTMF sent successfully with INFO", + call_id)); + } else if (tsx->status_code >= 300) { + PJ_LOG(4,(THIS_FILE, + "Call %d: Failed to send DTMF with INFO: %d/%.*s", + call_id, + tsx->status_code, + (int)tsx->status_text.slen, + tsx->status_text.ptr)); + } + } else if (tsx->role == PJSIP_ROLE_UAS && + tsx->state == PJSIP_TSX_STATE_TRYING) + { + /* Answer incoming INFO with 200/OK */ + pjsip_rx_data *rdata; + pjsip_tx_data *tdata; + pj_status_t status; + + rdata = e->body.tsx_state.src.rdata; + + if (rdata->msg_info.msg->body) { + status = pjsip_endpt_create_response(tsx->endpt, rdata, + 200, NULL, &tdata); + if (status == PJ_SUCCESS) + status = pjsip_tsx_send_msg(tsx, tdata); + + PJ_LOG(3,(THIS_FILE, "Call %d: incoming INFO:\n%.*s", + call_id, + (int)rdata->msg_info.msg->body->len, + rdata->msg_info.msg->body->data)); + } else { + status = pjsip_endpt_create_response(tsx->endpt, rdata, + 400, NULL, &tdata); + if (status == PJ_SUCCESS) + status = pjsip_tsx_send_msg(tsx, tdata); + } + } + } +} + + /* * Callback on media state changed event. * The action may connect the call to sound device, to file, or @@ -2862,6 +2928,53 @@ void console_app_main(const pj_str_t *uri_to_call) } break; + case '*': + /* Send DTMF with INFO */ + if (current_call == -1) { + + PJ_LOG(3,(THIS_FILE, "No current call")); + + } else { + const pj_str_t SIP_INFO = pj_str("INFO"); + pj_str_t digits; + int call = current_call; + int i; + pj_status_t status; + + if (!simple_input("DTMF strings to send (0-9*#A-B)", buf, + sizeof(buf))) + { + break; + } + + if (call != current_call) { + puts("Call has been disconnected"); + continue; + } + + digits = pj_str(buf); + for (i=0; i