示例#1
0
END_TEST

START_TEST(notify_6_3_5)
{
    nua_handle_t *nh;
    struct message *notify;
    struct event *response;
    sip_t *sip;

    S2_CASE("6.3.4", "NOTIFY server - terminate with error response to NOTIFY",
            "NUA receives SUBSCRIBE, sends 202 and NOTIFY. "
            "The subscription terminates when watcher "
            "returns 481 to NOTIFY.");

    nh = subscribe_to_nua("presence", SIPTAG_EXPIRES_STR("300"), TAG_END());

    nua_notify(nh,
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    nua_notify(nh,
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_open),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));

    nua_notify(nh,
               NUTAG_NEWSUB(1),
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_open),
               TAG_END());

    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
    response = s2_wait_for_event(nua_r_notify, 481);
    fail_unless(s2_event_substate(response) == nua_substate_terminated);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
    response = s2_wait_for_event(nua_r_notify, 481);
    fail_unless(s2_event_substate(response) == nua_substate_terminated);

    nua_handle_destroy(nh);
}
示例#2
0
static int luasofia_nua_handle_notify(lua_State *L)
{
    /* get and check first argument (should be a luasofia_nua_handle_t) */
    luasofia_nua_handle_t *lnh = (luasofia_nua_handle_t*) luaL_checkudata(L, 1, NUA_HANDLE_MTABLE);
    if (lnh->nh) {
        su_home_t *home = su_home_create();
        /* get and check second argument (should be a tag table) */
        tagi_t *tags = luasofia_tags_table_to_taglist(L, 2, home);

        nua_notify(lnh->nh, TAG_NEXT(tags));
        su_home_unref(home);
    }
    return 0;
}
示例#3
0
END_TEST

START_TEST(notify_6_3_2)
{
    nua_handle_t *nh;
    struct message *notify;
    sip_t *sip;

    S2_CASE("6.3.2", "NOTIFY server - automatic subscription termination",
            "NUA receives SUBSCRIBE, sends 202 and NOTIFY. "
            "The subscription terminates with timeout. ");

    nh = subscribe_to_nua("presence", SIPTAG_EXPIRES_STR("300"), TAG_END());

    nua_notify(nh,
               NUTAG_SUBSTATE(nua_substate_active),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    s2_nua_fast_forward(300, s2base->root);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "terminated"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    nua_handle_destroy(nh);
}
示例#4
0
END_TEST

START_TEST(notify_6_3_6)
{
    nua_handle_t *nh;
    struct event *subscribe;
    struct message *notify, *response;
    sip_t *sip;

    S2_CASE("6.3.6", "Explicit refresh with NUTAG_APPL_EVENT()",
            "Process subscription refresh by application");

    nua_set_params(nua,
                   NUTAG_APPL_METHOD("SUBSCRIBE"),
                   NUTAG_APPL_EVENT("presence"),
                   SIPTAG_ALLOW_EVENTS_STR("presence"),
                   TAG_END());
    fail_unless_event(nua_r_set_params, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    subscribe = s2_wait_for_event(nua_i_subscribe, 100);
    nh = subscribe->nh;
    nua_respond(nh, SIP_202_ACCEPTED,
                NUTAG_WITH_SAVED(subscribe->event),
                TAG_END());
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(202, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    s2_sip_free_message(response);

    nua_notify(nh,
               NUTAG_SUBSTATE(nua_substate_active),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    subscribe = s2_wait_for_event(nua_i_subscribe, 100);
    nh = subscribe->nh;
    nua_respond(nh, SIP_202_ACCEPTED,
                NUTAG_WITH_SAVED(subscribe->event),
                TAG_END());
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(202, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    s2_sip_free_message(response);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    /* Now clear list of application events */
    nua_set_params(nua,
                   NUTAG_APPL_EVENT(NULL),
                   NUTAG_SUB_EXPIRES(360),
                   TAG_END());
    fail_unless_event(nua_r_set_params, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    /* Automatically responded && refreshed */
    subscribe = s2_wait_for_event(nua_i_subscribe, 200);
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(200, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    fail_unless(response->sip->sip_expires->ex_delta == 360);
    s2_sip_free_message(response);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    nua_handle_destroy(nh);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "terminated"));
    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
}