Changeset 3021


Ignore:
Timestamp:
Nov 20, 2009 11:33:07 PM (14 years ago)
Author:
bennylp
Message:

More ticket #982 (MWI): support for Asterisk unsolicited MWI requests:

  • undo r3019 which put unsolicited MWI support in pjsua app only
  • put the unsolicited MWI support in PJSUA-LIB instead
  • unsolicited MWI is by default enabled
  • on_mwi_info() callback will be called just as the solicited MWI version
Location:
pjproject/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r3019 r3021  
    102102    unsigned                auto_answer; 
    103103    unsigned                duration; 
    104     pj_bool_t               unsolicited_mwi; 
    105104 
    106105#ifdef STEREO_DEMO 
     
    146145static pj_status_t create_ipv6_media_transports(void); 
    147146pj_status_t app_destroy(void); 
    148 static void enable_unsolicited_mwi(void); 
    149147 
    150148static void ringback_start(pjsua_call_id call_id); 
     
    197195    puts  ("  --publish           Send presence PUBLISH for this account"); 
    198196    puts  ("  --mwi               Subscribe to message summary/waiting indication"); 
    199     puts  ("  --unsolicited-mwi   Handle unsolicited MWI requests"); 
    200197    puts  ("  --use-100rel        Require reliable provisional response (100rel)"); 
    201198    puts  ("  --use-timer         Require SIP session timers"); 
     
    488485           OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, OPT_CONTACT_URI_PARAMS, 
    489486           OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD, 
    490            OPT_MWI, OPT_UNSOLICITED_MWI, OPT_NAMESERVER, OPT_STUN_SRV, 
     487           OPT_MWI, OPT_NAMESERVER, OPT_STUN_SRV, 
    491488           OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, 
    492489           OPT_AUTO_ANSWER, OPT_AUTO_PLAY, OPT_AUTO_PLAY_HANGUP, OPT_AUTO_LOOP, 
     
    541538        { "publish",    0, 0, OPT_PUBLISH}, 
    542539        { "mwi",        0, 0, OPT_MWI}, 
    543         { "unsolicited-mwi", 0, 0, OPT_UNSOLICITED_MWI}, 
    544540        { "use-100rel", 0, 0, OPT_100REL}, 
    545541        { "use-ims",    0, 0, OPT_USE_IMS}, 
     
    844840            break; 
    845841 
    846         case OPT_UNSOLICITED_MWI: 
    847             cfg->unsolicited_mwi = PJ_TRUE; 
    848             break; 
    849  
    850842        case OPT_100REL: /** 100rel */ 
    851843            cur_acc->require_100rel = PJ_TRUE; 
     
    19991991    { 
    20001992        pj_strcat2(&cfg, "--use-compact-form\n"); 
    2001     } 
    2002  
    2003     if (config->unsolicited_mwi) { 
    2004         pj_strcat2(&cfg, "--unsolicited-mwi\n"); 
    20051993    } 
    20061994 
     
    44084396        return status; 
    44094397 
    4410     /* Initialize unsolicited MWI */ 
    4411     if (app_config.unsolicited_mwi) 
    4412         enable_unsolicited_mwi(); 
    4413  
    44144398    /* Initialize our module to handle otherwise unhandled request */ 
    44154399    status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(), 
     
    50165000} 
    50175001 
    5018 /***************************************************************************** 
    5019  * Asterisk unsolicited MWI module 
    5020  */ 
    5021 static pj_bool_t mwi_on_rx_request(pjsip_rx_data *rdata) 
    5022 { 
    5023     pjsip_msg *msg = rdata->msg_info.msg; 
    5024     pj_str_t EVENT_HDR  = { "Event", 5 }; 
    5025     pj_str_t MWI = { "message-summary", 15 }; 
    5026     pjsip_event_hdr *eh; 
    5027     pj_str_t body; 
    5028  
    5029     if (pjsip_method_cmp(&msg->line.req.method, &pjsip_notify_method)!=0) { 
    5030         /* Only interested with NOTIFY request */ 
    5031         return PJ_FALSE; 
    5032     } 
    5033  
    5034     eh = (pjsip_event_hdr*) pjsip_msg_find_hdr_by_name(msg, &EVENT_HDR, NULL); 
    5035     if (!eh) { 
    5036         /* Something wrong with the request, it has no Event hdr */ 
    5037         return PJ_FALSE; 
    5038     } 
    5039  
    5040     if (pj_stricmp(&eh->event_type, &MWI) != 0) { 
    5041         /* Not MWI event */ 
    5042         return PJ_FALSE; 
    5043     } 
    5044  
    5045     /* Got unsolicited MWI request, respond with 200/OK first */ 
    5046     pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL, 
    5047                         NULL, NULL, NULL); 
    5048  
    5049  
    5050     PJ_LOG(3,(THIS_FILE, "Received MWI info:")); 
    5051  
    5052     if (rdata->msg_info.ctype) { 
    5053         const pjsip_ctype_hdr *ctype = rdata->msg_info.ctype; 
    5054  
    5055         PJ_LOG(3,(THIS_FILE, " Content-Type: %.*s/%.*s", 
    5056                   (int)ctype->media.type.slen, 
    5057                   ctype->media.type.ptr, 
    5058                   (int)ctype->media.subtype.slen, 
    5059                   ctype->media.subtype.ptr)); 
    5060     } 
    5061  
    5062     if (!rdata->msg_info.msg->body) { 
    5063         PJ_LOG(3,(THIS_FILE, "  no message body")); 
    5064         return PJ_TRUE; 
    5065     } 
    5066  
    5067     body.ptr = rdata->msg_info.msg->body->data; 
    5068     body.slen = rdata->msg_info.msg->body->len; 
    5069  
    5070     PJ_LOG(3,(THIS_FILE, " Body:\n%.*s", (int)body.slen, body.ptr)); 
    5071      
    5072     return PJ_TRUE; 
    5073 } 
    5074  
    5075 /* The module instance. */ 
    5076 static pjsip_module pjsua_mwi_mod =  
    5077 { 
    5078     NULL, NULL,                         /* prev, next.          */ 
    5079     { "mod-unsolicited-mwi", 19 },      /* Name.                */ 
    5080     -1,                                 /* Id                   */ 
    5081     PJSIP_MOD_PRIORITY_UA_PROXY_LAYER-1,/* Priority             */ 
    5082     NULL,                               /* load()               */ 
    5083     NULL,                               /* start()              */ 
    5084     NULL,                               /* stop()               */ 
    5085     NULL,                               /* unload()             */ 
    5086     &mwi_on_rx_request,                 /* on_rx_request()      */ 
    5087     NULL,                               /* on_rx_response()     */ 
    5088     NULL,                               /* on_tx_request.       */ 
    5089     NULL,                               /* on_tx_response()     */ 
    5090     NULL,                               /* on_tsx_state()       */ 
    5091 }; 
    5092  
    5093 static void enable_unsolicited_mwi(void) 
    5094 { 
    5095     pj_status_t status; 
    5096  
    5097     status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(),  
    5098                                          &pjsua_mwi_mod); 
    5099     if (status != PJ_SUCCESS) 
    5100         pjsua_perror(THIS_FILE, "Error registering MWI module", status); 
    5101 } 
    5102  
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r2968 r3021  
    10031003 
    10041004    /** 
     1005     * Handle unsolicited NOTIFY requests containing message waiting  
     1006     * indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests  
     1007     * which are not requested by client with SUBSCRIBE request.  
     1008     * 
     1009     * If this is enabled, the library will respond 200/OK to the NOTIFY 
     1010     * request and forward the request to \a on_mwi_info() callback. 
     1011     * 
     1012     * See also \a mwi_enabled field #on pjsua_acc_config. 
     1013     * 
     1014     * Default: PJ_TRUE 
     1015     * 
     1016     */ 
     1017    pj_bool_t       enable_unsolicited_mwi; 
     1018 
     1019    /** 
    10051020     * Specify Session Timer settings, see #pjsip_timer_setting.  
    10061021     * Note that this setting can be further customized in account  
     
    18831898 
    18841899    /** 
    1885      * Enable message summary and message waiting indication subscription 
    1886      * (RFC 3842) for this account. 
     1900     * Subscribe to message waiting indication events (RFC 3842). 
     1901     * 
     1902     * See also \a enable_unsolicited_mwi field on #pjsua_config. 
    18871903     * 
    18881904     * Default: no 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r3013 r3021  
    102102    cfg->stun_ignore_failure = PJ_TRUE; 
    103103    cfg->force_lr = PJ_TRUE; 
     104    cfg->enable_unsolicited_mwi = PJ_TRUE; 
    104105#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 
    105106    cfg->use_srtp = PJSUA_DEFAULT_USE_SRTP; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r3009 r3021  
    20762076 
    20772077 
     2078/*************************************************************************** 
     2079 * Unsolicited MWI 
     2080 */ 
     2081static pj_bool_t unsolicited_mwi_on_rx_request(pjsip_rx_data *rdata) 
     2082{ 
     2083    pjsip_msg *msg = rdata->msg_info.msg; 
     2084    pj_str_t EVENT_HDR  = { "Event", 5 }; 
     2085    pj_str_t MWI = { "message-summary", 15 }; 
     2086    pjsip_event_hdr *eh; 
     2087 
     2088    if (pjsip_method_cmp(&msg->line.req.method, &pjsip_notify_method)!=0) { 
     2089        /* Only interested with NOTIFY request */ 
     2090        return PJ_FALSE; 
     2091    } 
     2092 
     2093    eh = (pjsip_event_hdr*) pjsip_msg_find_hdr_by_name(msg, &EVENT_HDR, NULL); 
     2094    if (!eh) { 
     2095        /* Something wrong with the request, it has no Event hdr */ 
     2096        return PJ_FALSE; 
     2097    } 
     2098 
     2099    if (pj_stricmp(&eh->event_type, &MWI) != 0) { 
     2100        /* Not MWI event */ 
     2101        return PJ_FALSE; 
     2102    } 
     2103 
     2104    /* Got unsolicited MWI request, respond with 200/OK first */ 
     2105    pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL, 
     2106                        NULL, NULL, NULL); 
     2107 
     2108 
     2109    /* Call callback */ 
     2110    if (pjsua_var.ua_cfg.cb.on_mwi_info) { 
     2111        pjsua_acc_id acc_id; 
     2112        pjsua_mwi_info mwi_info; 
     2113 
     2114        acc_id = pjsua_acc_find_for_incoming(rdata); 
     2115 
     2116        pj_bzero(&mwi_info, sizeof(mwi_info)); 
     2117        mwi_info.rdata = rdata; 
     2118 
     2119        (*pjsua_var.ua_cfg.cb.on_mwi_info)(acc_id, &mwi_info); 
     2120    } 
     2121 
     2122     
     2123    return PJ_TRUE; 
     2124} 
     2125 
     2126/* The module instance. */ 
     2127static pjsip_module pjsua_unsolicited_mwi_mod =  
     2128{ 
     2129    NULL, NULL,                         /* prev, next.          */ 
     2130    { "mod-unsolicited-mwi", 19 },      /* Name.                */ 
     2131    -1,                                 /* Id                   */ 
     2132    PJSIP_MOD_PRIORITY_APPLICATION,     /* Priority             */ 
     2133    NULL,                               /* load()               */ 
     2134    NULL,                               /* start()              */ 
     2135    NULL,                               /* stop()               */ 
     2136    NULL,                               /* unload()             */ 
     2137    &unsolicited_mwi_on_rx_request,     /* on_rx_request()      */ 
     2138    NULL,                               /* on_rx_response()     */ 
     2139    NULL,                               /* on_tx_request.       */ 
     2140    NULL,                               /* on_tx_response()     */ 
     2141    NULL,                               /* on_tsx_state()       */ 
     2142}; 
     2143 
     2144static pj_status_t enable_unsolicited_mwi(void) 
     2145{ 
     2146    pj_status_t status; 
     2147 
     2148    status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(),  
     2149                                         &pjsua_unsolicited_mwi_mod); 
     2150    if (status != PJ_SUCCESS) 
     2151        pjsua_perror(THIS_FILE, "Error registering unsolicited MWI module",  
     2152                     status); 
     2153 
     2154    return status; 
     2155} 
     2156 
     2157 
     2158 
    20782159/***************************************************************************/ 
    20792160 
     
    21512232    } 
    21522233 
     2234    if (pjsua_var.ua_cfg.enable_unsolicited_mwi) { 
     2235        pj_status_t status = enable_unsolicited_mwi(); 
     2236        if (status != PJ_SUCCESS) 
     2237            return status; 
     2238    } 
     2239 
    21532240    return PJ_SUCCESS; 
    21542241} 
Note: See TracChangeset for help on using the changeset viewer.