Ignore:
Timestamp:
Aug 20, 2006 9:12:19 AM (18 years ago)
Author:
bennylp
Message:

Added initial "norefersub" (RFC 4488) implementation in PJSUA-LIB, and also properly register all supported SIP method, accepted content type, and supported extensions to endpoint.

File:
1 edited

Legend:

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

    r660 r688  
    9595    pjsip_inv_callback inv_cb; 
    9696    unsigned i; 
     97    const pj_str_t str_norefersub = { "norefersub", 10 }; 
    9798    pj_status_t status; 
    9899 
     
    116117    status = pjsip_inv_usage_init(pjsua_var.endpt, &inv_cb); 
    117118    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     119 
     120    /* Add "norefersub" in Supported header */ 
     121    pjsip_endpt_add_capability(pjsua_var.endpt, NULL, PJSIP_H_SUPPORTED, 
     122                               NULL, 1, &str_norefersub); 
    118123 
    119124    return status; 
     
    21252130    int new_call; 
    21262131    const pj_str_t str_refer_to = { "Refer-To", 8}; 
     2132    const pj_str_t str_refer_sub = { "Refer-Sub", 9 }; 
    21272133    pjsip_generic_string_hdr *refer_to; 
     2134    pjsip_generic_string_hdr *refer_sub; 
     2135    pj_bool_t no_refer_sub = PJ_FALSE; 
    21282136    char *uri; 
    21292137    pj_str_t tmp; 
    2130     struct pjsip_evsub_user xfer_cb; 
    21312138    pjsip_status_code code; 
    21322139    pjsip_evsub *sub; 
     
    21472154    } 
    21482155 
     2156    /* Find optional Refer-Sub header */ 
     2157    refer_sub = (pjsip_generic_string_hdr*) 
     2158        pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_sub, NULL); 
     2159 
     2160    if (refer_sub) { 
     2161        if (!pj_strnicmp2(&refer_sub->hvalue, "true", 4)==0) 
     2162            no_refer_sub = PJ_TRUE; 
     2163    } 
     2164 
     2165 
    21492166    /* Notify callback */ 
    21502167    code = PJSIP_SC_OK; 
     
    21672184              refer_to->hvalue.ptr)); 
    21682185 
    2169     /* Init callback */ 
    2170     pj_bzero(&xfer_cb, sizeof(xfer_cb)); 
    2171     xfer_cb.on_evsub_state = &xfer_on_evsub_state; 
    2172  
    2173     /* Create transferee event subscription */ 
    2174     status = pjsip_xfer_create_uas( inv->dlg, &xfer_cb, rdata, &sub); 
    2175     if (status != PJ_SUCCESS) { 
    2176         pjsua_perror(THIS_FILE, "Unable to create xfer uas", status); 
    2177         pjsip_dlg_respond( inv->dlg, rdata, 500, NULL, NULL, NULL); 
    2178         return; 
    2179     } 
    2180  
    2181     /* Accept the REFER request, send 200 (OK). */ 
    2182     pjsip_xfer_accept(sub, rdata, code, NULL); 
    2183  
    2184     /* Create initial NOTIFY request */ 
    2185     status = pjsip_xfer_notify( sub, PJSIP_EVSUB_STATE_ACTIVE, 
    2186                                 100, NULL, &tdata); 
    2187     if (status != PJ_SUCCESS) { 
    2188         pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER", status); 
    2189         return; 
    2190     } 
    2191  
    2192     /* Send initial NOTIFY request */ 
    2193     status = pjsip_xfer_send_request( sub, tdata); 
    2194     if (status != PJ_SUCCESS) { 
    2195         pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER", status); 
    2196         return; 
     2186    if (no_refer_sub) { 
     2187        /* 
     2188         * Always answer with 200. 
     2189         */ 
     2190        pjsip_tx_data *tdata; 
     2191        const pj_str_t str_false = { "false", 5}; 
     2192        pjsip_hdr *hdr; 
     2193 
     2194        status = pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata); 
     2195        if (status != PJ_SUCCESS) { 
     2196            pjsua_perror(THIS_FILE, "Unable to create 200 response to REFER", 
     2197                         status); 
     2198            return; 
     2199        } 
     2200 
     2201        /* Add Refer-Sub header */ 
     2202        hdr = (pjsip_hdr*)  
     2203               pjsip_generic_string_hdr_create(tdata->pool, &str_refer_sub, 
     2204                                              &str_false); 
     2205        pjsip_msg_add_hdr(tdata->msg, hdr); 
     2206 
     2207 
     2208        /* Send answer */ 
     2209        status = pjsip_dlg_send_response(inv->dlg, pjsip_rdata_get_tsx(rdata), 
     2210                                         tdata); 
     2211        if (status != PJ_SUCCESS) { 
     2212            pjsua_perror(THIS_FILE, "Unable to create 200 response to REFER", 
     2213                         status); 
     2214            return; 
     2215        } 
     2216 
     2217        /* Don't have subscription */ 
     2218        sub = NULL; 
     2219 
     2220    } else { 
     2221        struct pjsip_evsub_user xfer_cb; 
     2222        pjsip_hdr hdr_list; 
     2223 
     2224        /* Init callback */ 
     2225        pj_bzero(&xfer_cb, sizeof(xfer_cb)); 
     2226        xfer_cb.on_evsub_state = &xfer_on_evsub_state; 
     2227 
     2228        /* Init additional header list to be sent with REFER response */ 
     2229        pj_list_init(&hdr_list); 
     2230 
     2231        /* Create transferee event subscription */ 
     2232        status = pjsip_xfer_create_uas( inv->dlg, &xfer_cb, rdata, &sub); 
     2233        if (status != PJ_SUCCESS) { 
     2234            pjsua_perror(THIS_FILE, "Unable to create xfer uas", status); 
     2235            pjsip_dlg_respond( inv->dlg, rdata, 500, NULL, NULL, NULL); 
     2236            return; 
     2237        } 
     2238 
     2239        /* If there's Refer-Sub header and the value is "true", send back 
     2240         * Refer-Sub in the response with value "true" too. 
     2241         */ 
     2242        if (refer_sub) { 
     2243            const pj_str_t str_true = { "true", 4 }; 
     2244            pjsip_hdr *hdr; 
     2245 
     2246            hdr = (pjsip_hdr*)  
     2247                   pjsip_generic_string_hdr_create(inv->dlg->pool,  
     2248                                                   &str_refer_sub, 
     2249                                                   &str_true); 
     2250            pj_list_push_back(&hdr_list, hdr); 
     2251 
     2252        } 
     2253 
     2254        /* Accept the REFER request, send 200 (OK). */ 
     2255        pjsip_xfer_accept(sub, rdata, code, &hdr_list); 
     2256 
     2257        /* Create initial NOTIFY request */ 
     2258        status = pjsip_xfer_notify( sub, PJSIP_EVSUB_STATE_ACTIVE, 
     2259                                    100, NULL, &tdata); 
     2260        if (status != PJ_SUCCESS) { 
     2261            pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER",  
     2262                         status); 
     2263            return; 
     2264        } 
     2265 
     2266        /* Send initial NOTIFY request */ 
     2267        status = pjsip_xfer_send_request( sub, tdata); 
     2268        if (status != PJ_SUCCESS) { 
     2269            pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER", status); 
     2270            return; 
     2271        } 
    21972272    } 
    21982273 
     
    22122287    if (status != PJ_SUCCESS) { 
    22132288 
    2214         /* Notify xferer about the error */ 
    2215         status = pjsip_xfer_notify(sub, PJSIP_EVSUB_STATE_TERMINATED, 
    2216                                    500, NULL, &tdata); 
    2217         if (status != PJ_SUCCESS) { 
    2218             pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER",  
    2219                           status); 
    2220             return; 
    2221         } 
    2222         status = pjsip_xfer_send_request(sub, tdata); 
    2223         if (status != PJ_SUCCESS) { 
    2224             pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER",  
    2225                           status); 
    2226             return; 
     2289        /* Notify xferer about the error (if we have subscription) */ 
     2290        if (sub) { 
     2291            status = pjsip_xfer_notify(sub, PJSIP_EVSUB_STATE_TERMINATED, 
     2292                                       500, NULL, &tdata); 
     2293            if (status != PJ_SUCCESS) { 
     2294                pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER",  
     2295                              status); 
     2296                return; 
     2297            } 
     2298            status = pjsip_xfer_send_request(sub, tdata); 
     2299            if (status != PJ_SUCCESS) { 
     2300                pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER",  
     2301                              status); 
     2302                return; 
     2303            } 
    22272304        } 
    22282305        return; 
    22292306    } 
    22302307 
    2231     /* Put the server subscription in inv_data. 
    2232      * Subsequent state changed in pjsua_inv_on_state_changed() will be 
    2233      * reported back to the server subscription. 
    2234      */ 
    2235     pjsua_var.calls[new_call].xfer_sub = sub; 
    2236  
    2237     /* Put the invite_data in the subscription. */ 
    2238     pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id,  
    2239                              &pjsua_var.calls[new_call]); 
     2308    if (sub) { 
     2309        /* Put the server subscription in inv_data. 
     2310         * Subsequent state changed in pjsua_inv_on_state_changed() will be 
     2311         * reported back to the server subscription. 
     2312         */ 
     2313        pjsua_var.calls[new_call].xfer_sub = sub; 
     2314 
     2315        /* Put the invite_data in the subscription. */ 
     2316        pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id,  
     2317                                 &pjsua_var.calls[new_call]); 
     2318    } 
    22402319} 
    22412320 
Note: See TracChangeset for help on using the changeset viewer.