Fix when the subscription_terminated callback is called for subscription handlers.
[asterisk/asterisk.git] / res / res_pjsip_pubsub.c
index ae31f5c..ecc0059 100644 (file)
@@ -962,15 +962,6 @@ static void pubsub_on_evsub_state(pjsip_evsub *evsub, pjsip_event *event)
                return;
        }
 
-       if (event->type == PJSIP_EVENT_RX_MSG) {
-               sub->handler->subscription_terminated(sub, event->body.rx_msg.rdata);
-       }
-
-       if (event->type == PJSIP_EVENT_TSX_STATE &&
-                       event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
-               sub->handler->subscription_terminated(sub, event->body.tsx_state.src.rdata);
-       }
-
        if (sub->handler->subscription_shutdown) {
                sub->handler->subscription_shutdown(sub);
        }
@@ -1052,6 +1043,11 @@ static void pubsub_on_rx_refresh(pjsip_evsub *evsub, pjsip_rx_data *rdata,
                return;
        }
 
+       if (pjsip_evsub_get_state(sub->evsub) == PJSIP_EVSUB_STATE_TERMINATED) {
+               sub->handler->subscription_terminated(sub, rdata);
+               return;
+       }
+
        sub->handler->resubscribe(sub, rdata, &response_data);
 
        if (!response_data_changed(&response_data)) {