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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.