Ignore:
Timestamp:
Feb 7, 2006 6:48:01 PM (18 years ago)
Author:
bennylp
Message:

Tested initial implementation: basic UAC, client registration, authentication, etc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c

    r139 r141  
    107107static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata) 
    108108{ 
     109    pjsip_dialog *dlg; 
     110 
    109111    /* Ignore requests outside dialog */ 
    110     if (pjsip_rdata_get_dlg(rdata) == NULL) 
     112    dlg = pjsip_rdata_get_dlg(rdata); 
     113    if (dlg == NULL) 
    111114        return PJ_FALSE; 
    112115 
    113     /* Ignore all. */ 
     116    /* Answer BYE with 200/OK. */ 
     117    if (rdata->msg_info.msg->line.req.method.id == PJSIP_BYE_METHOD) { 
     118        pj_status_t status; 
     119        pjsip_tx_data *tdata; 
     120 
     121        status = pjsip_dlg_create_response(dlg, rdata, 200, NULL, &tdata); 
     122        if (status == PJ_SUCCESS) 
     123            status = pjsip_dlg_send_response(dlg, pjsip_rdata_get_tsx(rdata), 
     124                                             tdata); 
     125 
     126        return status==PJ_SUCCESS ? PJ_TRUE : PJ_FALSE; 
     127    } 
     128 
    114129    return PJ_FALSE; 
    115130} 
     
    915930 
    916931    case PJSIP_INV_STATE_DISCONNECTED: 
    917     case PJSIP_INV_STATE_TERMINATED: 
    918932        /* No need to do anything. */ 
    919933        PJ_TODO(RETURN_A_PROPER_STATUS_CODE_HERE); 
     
    10671081    pjsip_transaction *tsx = e->body.tsx_state.tsx; 
    10681082    pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx); 
     1083    pj_status_t status; 
    10691084 
    10701085    PJ_ASSERT_ON_FAIL(tsx && dlg, return); 
    10711086     
    1072     if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1087    if (tsx == s->invite_tsx) { 
    10731088 
    10741089        switch (tsx->state) { 
     
    10931108                inv_set_state(s, PJSIP_INV_STATE_CONNECTING, e); 
    10941109 
     1110            } else if (tsx->status_code==401 || tsx->status_code==407) { 
     1111 
     1112                /* Handle authentication failure: 
     1113                 * Resend the request with Authorization header. 
     1114                 */ 
     1115                pjsip_tx_data *tdata; 
     1116 
     1117                status = pjsip_auth_clt_reinit_req(&s->dlg->auth_sess,  
     1118                                                   e->body.tsx_state.src.rdata, 
     1119                                                   tsx->last_tx, 
     1120                                                   &tdata); 
     1121 
     1122                if (status != PJ_SUCCESS) { 
     1123 
     1124                    /* Does not have proper credentials.  
     1125                     * End the session. 
     1126                     */ 
     1127                    inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
     1128 
     1129                } else { 
     1130 
     1131                    /* Restart session. */ 
     1132                    s->state = PJSIP_INV_STATE_NULL; 
     1133                    s->invite_tsx = NULL; 
     1134 
     1135                    /* Send the request. */ 
     1136                    status = pjsip_inv_send_msg(s, tdata, NULL ); 
     1137                } 
     1138 
    10951139            } else { 
     1140 
    10961141                inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
     1142 
    10971143            } 
    10981144            break; 
     
    11161162            } else  { 
    11171163                inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
    1118                 inv_set_state(s, PJSIP_INV_STATE_TERMINATED, e); 
    11191164            } 
    11201165            break; 
     
    11361181    PJ_ASSERT_ON_FAIL(tsx && dlg, return); 
    11371182 
    1138     if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1183    if (tsx == s->invite_tsx) { 
    11391184        switch (tsx->state) { 
    11401185        case PJSIP_TSX_STATE_PROCEEDING: 
     
    11511196            /* This happens on transport error */ 
    11521197            inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
    1153             inv_set_state(s, PJSIP_INV_STATE_TERMINATED, e); 
    11541198            break; 
    11551199        default: 
     
    11681212    PJ_ASSERT_ON_FAIL(tsx && dlg, return); 
    11691213 
    1170     if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1214    if (tsx == s->invite_tsx) { 
    11711215 
    11721216        switch (tsx->state) { 
     
    12071251            } else  { 
    12081252                inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
    1209                 inv_set_state(s, PJSIP_INV_STATE_TERMINATED, e); 
    12101253            } 
    12111254            break; 
     
    12441287        } 
    12451288 
     1289    } else if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1290 
     1291        /* Ignore previously failed INVITE transaction event 
     1292         * (e.g. when rejected with 401/407) 
     1293         */ 
     1294 
    12461295    } else { 
    12471296        pj_assert(!"Unexpected transaction type"); 
     
    12561305    PJ_ASSERT_ON_FAIL(tsx && dlg, return); 
    12571306 
    1258     if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1307    if (tsx == s->invite_tsx) { 
    12591308 
    12601309        switch (tsx->state) { 
     
    12701319            if (tsx->status_code/100 != 2) { 
    12711320                inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
    1272                 inv_set_state(s, PJSIP_INV_STATE_TERMINATED, e); 
    12731321            } 
    12741322            break; 
     
    12971345        inv_set_state(s, PJSIP_INV_STATE_DISCONNECTED, e); 
    12981346 
    1299     } else if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1347    } else if (tsx == s->invite_tsx) { 
    13001348         
    13011349        switch (tsx->state) { 
     
    13081356        } 
    13091357 
     1358    } else if (tsx->method.id == PJSIP_INVITE_METHOD) { 
     1359 
     1360        /* Re-INVITE */ 
    13101361 
    13111362    } else { 
Note: See TracChangeset for help on using the changeset viewer.