Changeset 5838


Ignore:
Timestamp:
Jul 25, 2018 9:58:37 AM (6 years ago)
Author:
nanang
Message:

Close #2132: Updated pjsua_acc_find_for_incoming() to use weighted score algo in selecting account, where transport type match has higher priority.

File:
1 edited

Legend:

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

    r5833 r5838  
    29942994    pjsip_sip_uri *sip_uri; 
    29952995    pjsua_acc_id id = PJSUA_INVALID_ID; 
     2996    int max_score; 
    29962997    unsigned i; 
    29972998 
     
    30263027    sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    30273028 
    3028     /* Find account which has matching username and domain. */ 
     3029    /* Select account by weighted score. Matching priority order is: 
     3030     * transport type (matched or not set), domain part, and user part. 
     3031     * Note that the transport type has higher priority as unmatched 
     3032     * transport type may cause failure in sending response. 
     3033     */ 
     3034    max_score = 0; 
    30293035    for (i=0; i < pjsua_var.acc_cnt; ++i) { 
    30303036        unsigned acc_id = pjsua_var.acc_ids[i]; 
    30313037        pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    3032  
    3033         if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0 && 
    3034             pj_stricmp(&acc->srv_domain, &sip_uri->host)==0)  
     3038        int score = 0; 
     3039 
     3040        if (!acc->valid) 
     3041            continue; 
     3042 
     3043        /* Match transport type */ 
     3044        if (acc->tp_type == rdata->tp_info.transport->key.type || 
     3045            acc->tp_type == PJSIP_TRANSPORT_UNSPECIFIED) 
    30353046        { 
    3036             /* Match ! */ 
     3047            score |= 4; 
     3048        } 
     3049 
     3050        /* Match domain */ 
     3051        if (pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) { 
     3052            score |= 2; 
     3053        } 
     3054 
     3055        /* Match username */ 
     3056        if (pj_stricmp(&acc->user_part, &sip_uri->user)==0) { 
     3057            score |= 1; 
     3058        } 
     3059 
     3060        if (score > max_score) { 
    30373061            id = acc_id; 
    3038             goto on_return; 
    3039         } 
    3040     } 
    3041  
    3042     /* No matching account, try match domain part only. */ 
    3043     for (i=0; i < pjsua_var.acc_cnt; ++i) { 
    3044         unsigned acc_id = pjsua_var.acc_ids[i]; 
    3045         pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    3046  
    3047         if (acc->valid && pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) { 
    3048             /* Match ! */ 
    3049             id = acc_id; 
    3050             goto on_return; 
    3051         } 
    3052     } 
    3053  
    3054     /* No matching account, try match user part (and transport type) only. */ 
    3055     for (i=0; i < pjsua_var.acc_cnt; ++i) { 
    3056         unsigned acc_id = pjsua_var.acc_ids[i]; 
    3057         pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    3058  
    3059         if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0) { 
    3060             if (acc->tp_type != PJSIP_TRANSPORT_UNSPECIFIED && 
    3061                 acc->tp_type != rdata->tp_info.transport->key.type) 
    3062             { 
    3063                 continue; 
    3064             } 
    3065  
    3066             /* Match ! */ 
    3067             id = acc_id; 
    3068             goto on_return; 
     3062            max_score = score; 
    30693063        } 
    30703064    } 
Note: See TracChangeset for help on using the changeset viewer.