Changeset 5195


Ignore:
Timestamp:
Nov 6, 2015 7:55:38 AM (8 years ago)
Author:
riza
Message:

Re #1895: Terminate subscription when receiving non 2xx Notify response without Retry-After header.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-simple/evsub.c

    r5178 r5195  
    254254 
    255255/* Static vars. */ 
    256 static const pj_str_t STR_EVENT      = { "Event", 5 }; 
    257 static const pj_str_t STR_EVENT_S    = { "o", 1 }; 
    258 static const pj_str_t STR_SUB_STATE  = { "Subscription-State", 18 }; 
    259 static const pj_str_t STR_TERMINATED = { "terminated", 10 }; 
    260 static const pj_str_t STR_ACTIVE     = { "active", 6 }; 
    261 static const pj_str_t STR_PENDING    = { "pending", 7 }; 
    262 static const pj_str_t STR_TIMEOUT    = { "timeout", 7}; 
     256static const pj_str_t STR_EVENT        = { "Event", 5 }; 
     257static const pj_str_t STR_EVENT_S      = { "o", 1 }; 
     258static const pj_str_t STR_SUB_STATE    = { "Subscription-State", 18 }; 
     259static const pj_str_t STR_TERMINATED   = { "terminated", 10 }; 
     260static const pj_str_t STR_ACTIVE       = { "active", 6 }; 
     261static const pj_str_t STR_PENDING      = { "pending", 7 }; 
     262static const pj_str_t STR_TIMEOUT      = { "timeout", 7}; 
     263static const pj_str_t STR_RETRY_AFTER  = { "Retry-After", 11 }; 
    263264 
    264265 
     
    21572158    } else if (pjsip_method_cmp(&tsx->method, &pjsip_notify_method)==0) { 
    21582159 
    2159         /* Handle authentication */  
     2160        /* Handle authentication */ 
    21602161        if (tsx->state == PJSIP_TSX_STATE_COMPLETED && 
    21612162            (tsx->status_code==401 || tsx->status_code==407)) 
    2162         { 
    2163             pjsip_rx_data *rdata = event->body.tsx_state.src.rdata; 
     2163        {            
    21642164            pjsip_tx_data *tdata; 
    21652165            pj_status_t status; 
    2166  
    2167             status = pjsip_auth_clt_reinit_req( &sub->dlg->auth_sess, rdata,  
    2168                                                 tsx->last_tx, &tdata); 
     2166            pjsip_rx_data *rdata = event->body.tsx_state.src.rdata; 
     2167 
     2168            status = pjsip_auth_clt_reinit_req(&sub->dlg->auth_sess, rdata, 
     2169                                               tsx->last_tx, &tdata); 
    21692170            if (status == PJ_SUCCESS) 
    2170                 status = pjsip_dlg_send_request( sub->dlg, tdata, -1, NULL ); 
     2171                status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL); 
    21712172 
    21722173            if (status != PJ_SUCCESS) { 
    21732174                /* Can't authenticate. Terminate session (?) */ 
    2174                 set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL,  
     2175                set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, 
    21752176                          &tsx->status_text); 
    21762177                return; 
     
    21782179 
    21792180        } 
    2180         /* 
    2181          * Terminate event usage if we receive 481, 408, and 7 class 
    2182          * responses. 
    2183          */ 
    2184         if (sub->state != PJSIP_EVSUB_STATE_TERMINATED && 
    2185             (tsx->status_code==481 || tsx->status_code==408 || 
    2186              tsx->status_code/100 == 7)) 
    2187         { 
    2188             set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event, 
    2189                       &tsx->status_text); 
     2181 
     2182        if (sub->state == PJSIP_EVSUB_STATE_TERMINATED) 
    21902183            return; 
    2191         } 
    2192  
     2184 
     2185        /* NOTIFY failure check */ 
     2186        if (tsx->status_code/100 != 2) { 
     2187            pj_bool_t should_terminate_sub = PJ_FALSE; 
     2188 
     2189            if (event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { 
     2190                if (tsx->status_code == 481) { 
     2191                    should_terminate_sub = PJ_TRUE; 
     2192                } else { 
     2193                    pjsip_retry_after_hdr *retry_after; 
     2194                    pjsip_rx_data *rdata = event->body.tsx_state.src.rdata;; 
     2195                    pjsip_msg *msg = rdata->msg_info.msg;                    
     2196 
     2197                    retry_after = (pjsip_retry_after_hdr*) 
     2198                       pjsip_msg_find_hdr_by_name(msg, &STR_RETRY_AFTER, NULL); 
     2199 
     2200                    if (!retry_after) { 
     2201                        should_terminate_sub = PJ_TRUE; 
     2202                    } 
     2203                } 
     2204            } else if (event->body.tsx_state.type == PJSIP_EVENT_TIMER) { 
     2205                if (tsx->status_code == 408) { 
     2206                    should_terminate_sub = PJ_TRUE; 
     2207                } 
     2208            } 
     2209 
     2210            /* 
     2211             * Terminate event usage if we receive non 2xx without retry_after 
     2212             * parameter, 481, 408 responses. 
     2213             */ 
     2214            if (should_terminate_sub) { 
     2215                set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event, 
     2216                          &tsx->status_text); 
     2217                return; 
     2218            } 
     2219        } 
    21932220    } else { 
    21942221 
Note: See TracChangeset for help on using the changeset viewer.