Changeset 995


Ignore:
Timestamp:
Feb 22, 2007 2:52:24 PM (17 years ago)
Author:
bennylp
Message:

Fixed ticket #132: dialog automatically insert Contact header when sending 3xx response (thanks Hozjan Vladimir for the report)

Location:
pjproject/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/config.c

    r983 r995  
    2222 
    2323static const char *id = "config.c"; 
    24 const char *PJ_VERSION = "0.5.10.1"; 
     24const char *PJ_VERSION = "0.5.10.1-trunk"; 
    2525 
    2626PJ_DEF(void) pj_dump_config(void) 
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r974 r995  
    22852285 
    22862286            } else { 
     2287                int st_code; 
     2288                char contact[120]; 
     2289                pj_str_t hname = { "Contact", 7 }; 
     2290                pj_str_t hvalue; 
     2291                pjsip_generic_string_hdr hcontact; 
     2292                pjsua_msg_data msg_data; 
     2293 
    22872294                if (!simple_input("Answer with code (100-699)", buf, sizeof(buf))) 
    22882295                    continue; 
    22892296                 
    2290                 if (my_atoi(buf) < 100) 
     2297                st_code = my_atoi(buf); 
     2298                if (st_code < 100) 
    22912299                    continue; 
     2300 
     2301                pjsua_msg_data_init(&msg_data); 
     2302 
     2303                if (st_code/100 == 3) { 
     2304                    if (!simple_input("Enter URL to be put in Contact",  
     2305                                      contact, sizeof(contact))) 
     2306                        continue; 
     2307                    hvalue = pj_str(contact); 
     2308                    pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue); 
     2309 
     2310                    pj_list_push_back(&msg_data.hdr_list, &hcontact); 
     2311                } 
    22922312 
    22932313                /* 
     
    23022322                } 
    23032323 
    2304                 pjsua_call_answer(current_call, my_atoi(buf), NULL, NULL); 
     2324                pjsua_call_answer(current_call, st_code, NULL, &msg_data); 
    23052325            } 
    23062326 
  • pjproject/trunk/pjsip/src/pjsip/sip_dialog.c

    r979 r995  
    11511151/* Add standard headers for certain types of response */ 
    11521152static void dlg_beautify_response(pjsip_dialog *dlg, 
     1153                                  pj_bool_t add_headers, 
    11531154                                  int st_code, 
    11541155                                  pjsip_tx_data *tdata) 
     
    11651166 
    11661167    /* Contact, Allow, Supported header. */ 
    1167     if (pjsip_method_creates_dialog(&cseq->method)) { 
     1168    if (add_headers && pjsip_method_creates_dialog(&cseq->method)) { 
    11681169        /* Add Contact header for 1xx, 2xx, 3xx and 485 response. */ 
    11691170        if (st_class==2 || st_class==3 || (st_class==1 && st_code != 100) || 
    11701171            st_code==485)  
    11711172        { 
     1173            pj_str_t hcontact = { "Contact", 7 }; 
     1174 
    11721175            /* Add contact header only if one is not present. */ 
    1173             if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0) { 
     1176            if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0 && 
     1177                pjsip_msg_find_hdr_by_name(tdata->msg, &hcontact, NULL) == 0)  
     1178            { 
    11741179                hdr = pjsip_hdr_clone(tdata->pool, dlg->local.contact); 
    11751180                pjsip_msg_add_hdr(tdata->msg, hdr); 
     
    12421247    pjsip_dlg_inc_lock(dlg); 
    12431248 
    1244     dlg_beautify_response(dlg, st_code, tdata); 
     1249    dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata); 
    12451250 
    12461251    /* Unlock the dialog. */ 
     
    12601265                                                const pj_str_t *st_text) 
    12611266{ 
    1262      
     1267    pjsip_hdr *hdr; 
     1268 
    12631269    PJ_ASSERT_RETURN(dlg && tdata && tdata->msg, PJ_EINVAL); 
    12641270    PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_RESPONSE_MSG, 
     
    12771283    } 
    12781284 
    1279     dlg_beautify_response(dlg, st_code, tdata); 
     1285    /* Remove existing Contact header (without this, when dialog sent  
     1286     * 180 and then 302, the Contact in 302 will not get updated). 
     1287     */ 
     1288    hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL); 
     1289    if (hdr) 
     1290        pj_list_erase(hdr); 
     1291 
     1292    /* Add tag etc. if necessary */ 
     1293    dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata); 
    12801294 
    12811295 
     
    13251339    /* Must acquire dialog first, to prevent deadlock */ 
    13261340    pjsip_dlg_inc_lock(dlg); 
     1341 
     1342    /* Last chance to add mandatory headers before the response is 
     1343     * sent. 
     1344     */ 
     1345    dlg_beautify_response(dlg, PJ_TRUE, tdata->msg->line.status.code, tdata); 
    13271346 
    13281347    /* If the dialog is locked to transport, make sure that transaction 
Note: See TracChangeset for help on using the changeset viewer.