Send Info Message with defined body

L
Lele
Mon, Jan 16, 2017 8:12 AM

Hi guys,

I'll try to send an Sip Info message on PJSIP_INV_STATE_CONFIRMED state
during enstablished dialog.

On on_call_state(.) pjsua Callback I have introduced the following code but
I obtained a crash:

void PjCallback::on_call_state(pjsua_call_id call_id, pjsip_event *e) {

 pj_status_t status;



 //Obtain detail information about the specified call

 pjsua_call_info ci;

 status = pjsua_call_get_info(call_id, &ci);



 //Obtain detail information about the specified call

pjsip_tx_data tdata;

//Pointer to tdata

 pjsip_tx_data  *pTdata;

//take the address of tdata

 pTdata = &tdata;

//Pointer to pointer tdata

 pjsip_tx_data  **ppTdata;

//take the address of pTdata using address of operator &

 ppTdata = &pTdata;



 //Get incoming message buffer

 pjsip_rx_data *rdata;

 rdata = e->body.tsx_state.src.rdata;

 

 //Get pjsip_dialog

pjsip_dialog *dlg;

 dlg = pjsip_rdata_get_dlg(rdata);



 //Get endpoint

 pjsip_endpoint *endpt = pjsua_get_pjsip_endpt();



 //Define standard xml to send in Info Sip body message

 pj_str_t xmlString = pj_str("<note>

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>");

 pj_str_t typeMessage = pj_str("text");

 pj_str_t subtypeMessage = pj_str("xml");



 pj_pool_t *poolTest;

 poolTest = pjsua_pool_create("infoMessage", 1000, 1000);

 pjsip_msg_body *createMessageBody;

 

 char dup[1500];

 

 switch(ci.state) {

 case PJSIP_INV_STATE_CONFIRMED:                  

       //Body Sip Info message

       createMessageBody = pjsip_msg_body_create(poolTest, &typeMessage,

&subtypeMessage, &xmlString);

       pjsip_print_text_body(createMessageBody, dup, sizeof(dup));

       

       //Create dialog request

       status = pjsip_dlg_create_request(dlg, &pjsip_info_method, -1,

ppTdata);

       if (status == PJ_SUCCESS) {

            //Send request (send Info message

            status = pjsip_dlg_send_request(dlg, pTdata, -1, NULL);

       }

       break;     

 default:

       ;

 }

}

I get a crash when I call pjsip_msg_body_create function. Where is the
problem? Thanks in advice.

Best Regards

Ll

Hi guys, I'll try to send an Sip Info message on PJSIP_INV_STATE_CONFIRMED state during enstablished dialog. On on_call_state(.) pjsua Callback I have introduced the following code but I obtained a crash: void PjCallback::on_call_state(pjsua_call_id call_id, pjsip_event *e) { pj_status_t status; //Obtain detail information about the specified call pjsua_call_info ci; status = pjsua_call_get_info(call_id, &ci); //Obtain detail information about the specified call pjsip_tx_data tdata; //Pointer to tdata pjsip_tx_data *pTdata; //take the address of tdata pTdata = &tdata; //Pointer to pointer tdata pjsip_tx_data **ppTdata; //take the address of pTdata using address of operator & ppTdata = &pTdata; //Get incoming message buffer pjsip_rx_data *rdata; rdata = e->body.tsx_state.src.rdata; //Get pjsip_dialog pjsip_dialog *dlg; dlg = pjsip_rdata_get_dlg(rdata); //Get endpoint pjsip_endpoint *endpt = pjsua_get_pjsip_endpt(); //Define standard xml to send in Info Sip body message pj_str_t xmlString = pj_str("<note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>"); pj_str_t typeMessage = pj_str("text"); pj_str_t subtypeMessage = pj_str("xml"); pj_pool_t *poolTest; poolTest = pjsua_pool_create("infoMessage", 1000, 1000); pjsip_msg_body *createMessageBody; char dup[1500]; switch(ci.state) { case PJSIP_INV_STATE_CONFIRMED: //Body Sip Info message createMessageBody = pjsip_msg_body_create(poolTest, &typeMessage, &subtypeMessage, &xmlString); pjsip_print_text_body(createMessageBody, dup, sizeof(dup)); //Create dialog request status = pjsip_dlg_create_request(dlg, &pjsip_info_method, -1, ppTdata); if (status == PJ_SUCCESS) { //Send request (send Info message status = pjsip_dlg_send_request(dlg, pTdata, -1, NULL); } break; default: ; } } I get a crash when I call pjsip_msg_body_create function. Where is the problem? Thanks in advice. Best Regards Ll
JL
JOHAN LANTZ
Mon, Jan 16, 2017 2:10 PM

Try something like this:

const pj_str_t SIP_INFO = pj_str("INFO”);

pjsua_msg_data msg_data;

char body[TU_MAX_SIP_INFO_BODY];

pjsua_msg_data_init(&msg_data);

msg_data.content_type = pj_str(“application/xxx");

pj_ansi_snprintf(body, sizeof(body), “MyInfoContent");

msg_data.msg_body = pj_str(body);

status = pjsua_call_send_request(call_id, &SIP_INFO,

                                     &msg_data);
Try something like this: const pj_str_t SIP_INFO = pj_str("INFO”); pjsua_msg_data msg_data; char body[TU_MAX_SIP_INFO_BODY]; pjsua_msg_data_init(&msg_data); msg_data.content_type = pj_str(“application/xxx"); pj_ansi_snprintf(body, sizeof(body), “MyInfoContent"); msg_data.msg_body = pj_str(body); status = pjsua_call_send_request(call_id, &SIP_INFO, &msg_data);