Ticket #192: pjsua_on_incoming_subscribe_cb_test.diff

File pjsua_on_incoming_subscribe_cb_test.diff, 3.0 KB (added by bennylp, 16 years ago)

Patch to pjsua_app.c to test the new callback functionality

  • pjsip-apps/src/pjsua/pjsua_app.c

     
    22502250    // Log already written. 
    22512251} 
    22522252 
     2253static int sub_pending_acc_id = PJSUA_INVALID_ID; 
     2254static pjsua_srv_pres *sub_pending_pres = NULL; 
    22532255 
    22542256/* 
     2257 * Handler on incoming SUBSCRIBE 
     2258 */ 
     2259static void on_incoming_subscribe(pjsua_acc_id acc_id, 
     2260                                  pjsua_srv_pres *srv_pres, 
     2261                                  pjsua_buddy_id buddy_id, 
     2262                                  const pj_str_t *from, 
     2263                                  pjsip_rx_data *rdata, 
     2264                                  pjsip_status_code *code, 
     2265                                  pj_str_t *reason, 
     2266                                  pjsua_msg_data *msg_data) 
     2267{ 
     2268    PJ_UNUSED_ARG(acc_id); 
     2269    PJ_UNUSED_ARG(srv_pres); 
     2270    PJ_UNUSED_ARG(from); 
     2271    PJ_UNUSED_ARG(rdata); 
     2272    PJ_UNUSED_ARG(reason); 
     2273    PJ_UNUSED_ARG(msg_data); 
     2274 
     2275    /* Accept immediately if incoming subscription is from friends */ 
     2276    if (buddy_id != PJSUA_INVALID_ID) { 
     2277        *code = 200; 
     2278        return; 
     2279    } 
     2280 
     2281    PJ_LOG(3,(THIS_FILE, "Incoming subscription request from %.*s", 
     2282              (int)from->slen, from->ptr)); 
     2283 
     2284    *code = 202; 
     2285 
     2286    sub_pending_acc_id = acc_id; 
     2287    sub_pending_pres = srv_pres; 
     2288} 
     2289 
     2290/* 
    22552291 * Handler on buddy state changed. 
    22562292 */ 
    22572293static void on_buddy_state(pjsua_buddy_id buddy_id) 
    22582294{ 
    22592295    pjsua_buddy_info info; 
     2296 
    22602297    pjsua_buddy_get_info(buddy_id, &info); 
    22612298 
    2262     PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", 
    2263               (int)info.uri.slen, 
    2264               info.uri.ptr, 
    2265               (int)info.status_text.slen, 
    2266               info.status_text.ptr)); 
     2299    if (info.sub_state == PJSIP_EVSUB_STATE_TERMINATED) { 
     2300        PJ_LOG(3,(THIS_FILE, "%.*s subscription terminated (reason=%.*s)", 
     2301                  (int)info.uri.slen, 
     2302                  info.uri.ptr, 
     2303                  (int)info.sub_term_reason.slen, 
     2304                  info.sub_term_reason.ptr)); 
     2305 
     2306    } else if (info.sub_state != PJSIP_EVSUB_STATE_NULL) { 
     2307        PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", 
     2308                  (int)info.uri.slen, 
     2309                  info.uri.ptr, 
     2310                  (int)info.status_text.slen, 
     2311                  info.status_text.ptr)); 
     2312    } 
    22672313} 
    22682314 
    22692315 
     
    37643810        case 'q': 
    37653811            goto on_exit; 
    37663812 
     3813        case 'b': 
     3814            if (!sub_pending_pres) 
     3815                break; 
    37673816 
     3817            if (menuin[1]=='a') { 
     3818                pjsua_pres_notify(sub_pending_acc_id, sub_pending_pres,  
     3819                                  PJSIP_EVSUB_STATE_ACTIVE, NULL, NULL,  
     3820                                  PJ_TRUE, NULL); 
     3821            } else { 
     3822                pj_str_t reason = pj_str("unauthorized"); 
     3823                pjsua_pres_notify(sub_pending_acc_id, sub_pending_pres,  
     3824                                  PJSIP_EVSUB_STATE_TERMINATED, NULL, &reason, 
     3825                                  PJ_TRUE, NULL); 
     3826            } 
     3827 
     3828            sub_pending_pres = NULL; 
     3829            sub_pending_acc_id = PJSUA_INVALID_ID; 
     3830            break; 
     3831 
    37683832        default: 
    37693833            if (menuin[0] != '\n' && menuin[0] != '\r') { 
    37703834                printf("Invalid input %s", menuin); 
     
    38133877    app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; 
    38143878    app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; 
    38153879    app_config.cfg.cb.on_reg_state = &on_reg_state; 
     3880    app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe; 
    38163881    app_config.cfg.cb.on_buddy_state = &on_buddy_state; 
    38173882    app_config.cfg.cb.on_pager = &on_pager; 
    38183883    app_config.cfg.cb.on_typing = &on_typing;