Ignore:
Timestamp:
Mar 2, 2006 9:18:58 PM (18 years ago)
Author:
bennylp
Message:

Added IM and composition indication, and tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r255 r268  
    2222 
    2323/* 
    24  * pjsua_inv.c 
     24 * pjsua_call.c 
    2525 * 
    26  * Invite session specific functionalities. 
     26 * Call (INVITE) related stuffs. 
    2727 */ 
    2828 
     
    260260    if (status != PJ_SUCCESS) { 
    261261 
    262         pjsip_dlg_respond(dlg, rdata, 500, NULL); 
     262        pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL); 
    263263 
    264264        // TODO: Need to delete dialog 
     
    286286        pjsua_perror(THIS_FILE, "Unable to create 100 response", status); 
    287287 
    288         pjsip_dlg_respond(dlg, rdata, 500, NULL); 
     288        pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL); 
    289289 
    290290        // TODO: Need to delete dialog 
     
    386386 
    387387 
    388     pjsua_ui_inv_on_state_changed(call->index, e); 
     388    pjsua_ui_on_call_state(call->index, e); 
    389389 
    390390    /* call->inv may be NULL now */ 
     
    464464         */ 
    465465        PJ_LOG(4,(THIS_FILE, "Received REFER without Refer-To header!")); 
    466         pjsip_dlg_respond( inv->dlg, rdata, 400, NULL); 
     466        pjsip_dlg_respond( inv->dlg, rdata, 400, NULL, NULL, NULL); 
    467467        return; 
    468468    } 
     
    482482    if (status != PJ_SUCCESS) { 
    483483        pjsua_perror(THIS_FILE, "Unable to create xfer uas", status); 
    484         pjsip_dlg_respond( inv->dlg, rdata, 500, NULL); 
     484        pjsip_dlg_respond( inv->dlg, rdata, 500, NULL, NULL, NULL); 
    485485        return; 
    486486    } 
     
    546546/* 
    547547 * This callback is called when transaction state has changed in INVITE 
    548  * session. We use this to trap incoming REFER request. 
     548 * session. We use this to trap: 
     549 *  - incoming REFER request. 
     550 *  - incoming MESSAGE request. 
    549551 */ 
    550552static void pjsua_call_on_tsx_state_changed(pjsip_inv_session *inv, 
     
    562564         */ 
    563565        on_call_transfered(call->inv, e->body.tsx_state.src.rdata); 
    564     } 
     566 
     567    } 
     568    else if (tsx->role==PJSIP_ROLE_UAS && 
     569             tsx->state==PJSIP_TSX_STATE_TRYING && 
     570             pjsip_method_cmp(&tsx->method, &pjsip_message_method)==0) 
     571    { 
     572        /* 
     573         * Incoming MESSAGE request! 
     574         */ 
     575        pjsip_rx_data *rdata; 
     576        pjsip_msg *msg; 
     577        pjsip_accept_hdr *accept_hdr; 
     578        pj_status_t status; 
     579 
     580        rdata = e->body.tsx_state.src.rdata; 
     581        msg = rdata->msg_info.msg; 
     582 
     583        /* Request MUST have message body, with Content-Type equal to 
     584         * "text/plain". 
     585         */ 
     586        if (pjsua_im_accept_pager(rdata, &accept_hdr) == PJ_FALSE) { 
     587 
     588            pjsip_hdr hdr_list; 
     589 
     590            pj_list_init(&hdr_list); 
     591            pj_list_push_back(&hdr_list, accept_hdr); 
     592 
     593            pjsip_dlg_respond( inv->dlg, rdata, PJSIP_SC_NOT_ACCEPTABLE_HERE,  
     594                               NULL, &hdr_list, NULL ); 
     595            return; 
     596        } 
     597 
     598        /* Respond with 200 first, so that remote doesn't retransmit in case 
     599         * the UI takes too long to process the message.  
     600         */ 
     601        status = pjsip_dlg_respond( inv->dlg, rdata, 200, NULL, NULL, NULL); 
     602 
     603        /* Process MESSAGE request */ 
     604        pjsua_im_process_pager(call->index, &inv->dlg->remote.info_str, 
     605                               &inv->dlg->local.info_str, rdata); 
     606    } 
     607 
    565608} 
    566609 
     
    10461089 
    10471090 
     1091/** 
     1092 * Send instant messaging inside INVITE session. 
     1093 */ 
     1094void pjsua_call_send_im(int call_index, const char *str) 
     1095{ 
     1096    pjsua_call *call; 
     1097    const pj_str_t mime_text = pj_str("text"); 
     1098    const pj_str_t mime_plain = pj_str("plain"); 
     1099    pj_str_t text; 
     1100    pjsip_tx_data *tdata; 
     1101    pj_status_t status; 
     1102 
     1103    call = &pjsua.calls[call_index]; 
     1104 
     1105    if (!call->inv) { 
     1106        PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 
     1107        return; 
     1108    } 
     1109 
     1110    /* Lock dialog. */ 
     1111    pjsip_dlg_inc_lock(call->inv->dlg); 
     1112     
     1113    /* Create request message. */ 
     1114    status = pjsip_dlg_create_request( call->inv->dlg, &pjsip_message_method, 
     1115                                       -1, &tdata); 
     1116    if (status != PJ_SUCCESS) { 
     1117        pjsua_perror(THIS_FILE, "Unable to create MESSAGE request", status); 
     1118        goto on_return; 
     1119    } 
     1120 
     1121    /* Add accept header. */ 
     1122    pjsip_msg_add_hdr( tdata->msg,  
     1123                       (pjsip_hdr*)pjsua_im_create_accept(tdata->pool)); 
     1124 
     1125    /* Create "text/plain" message body. */ 
     1126    tdata->msg->body = pjsip_msg_body_create( tdata->pool, &mime_text, 
     1127                                              &mime_plain,  
     1128                                              pj_cstr(&text, str)); 
     1129    if (tdata->msg->body == NULL) { 
     1130        pjsua_perror(THIS_FILE, "Unable to create msg body", PJ_ENOMEM); 
     1131        pjsip_tx_data_dec_ref(tdata); 
     1132        goto on_return; 
     1133    } 
     1134 
     1135    /* Send the request. */ 
     1136    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL); 
     1137    if (status != PJ_SUCCESS) { 
     1138        pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status); 
     1139        goto on_return; 
     1140    } 
     1141 
     1142on_return: 
     1143    pjsip_dlg_dec_lock(call->inv->dlg); 
     1144} 
     1145 
     1146 
     1147/** 
     1148 * Send IM typing indication inside INVITE session. 
     1149 */ 
     1150void pjsua_call_typing(int call_index, pj_bool_t is_typing) 
     1151{ 
     1152    pjsua_call *call; 
     1153    pjsip_tx_data *tdata; 
     1154    pj_status_t status; 
     1155 
     1156    call = &pjsua.calls[call_index]; 
     1157 
     1158    if (!call->inv) { 
     1159        PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 
     1160        return; 
     1161    } 
     1162 
     1163    /* Lock dialog. */ 
     1164    pjsip_dlg_inc_lock(call->inv->dlg); 
     1165     
     1166    /* Create request message. */ 
     1167    status = pjsip_dlg_create_request( call->inv->dlg, &pjsip_message_method, 
     1168                                       -1, &tdata); 
     1169    if (status != PJ_SUCCESS) { 
     1170        pjsua_perror(THIS_FILE, "Unable to create MESSAGE request", status); 
     1171        goto on_return; 
     1172    } 
     1173 
     1174    /* Create "application/im-iscomposing+xml" msg body. */ 
     1175    tdata->msg->body = pjsip_iscomposing_create_body(tdata->pool, is_typing, 
     1176                                                     NULL, NULL, -1); 
     1177 
     1178    /* Send the request. */ 
     1179    status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL); 
     1180    if (status != PJ_SUCCESS) { 
     1181        pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status); 
     1182        goto on_return; 
     1183    } 
     1184 
     1185on_return: 
     1186    pjsip_dlg_dec_lock(call->inv->dlg);} 
     1187 
     1188 
    10481189/* 
    10491190 * Terminate all calls. 
Note: See TracChangeset for help on using the changeset viewer.