static void mrcp_sofia_task_initialize(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); mrcp_sofia_server_config_t *sofia_config = sofia_agent->config; /* Initialize Sofia-SIP library and create event loop */ su_init(); sofia_agent->root = su_root_create(NULL); /* Create a user agent instance. The stack will call the 'event_callback()' * callback when events such as succesful registration to network, * an incoming call, etc, occur. */ sofia_agent->nua = nua_create( sofia_agent->root, /* Event loop */ mrcp_sofia_event_callback, /* Callback for processing events */ sofia_agent, /* Additional data to pass to callback */ NUTAG_URL(sofia_agent->sip_bind_str), /* Address to bind to */ NUTAG_AUTOANSWER(0), NUTAG_APPL_METHOD("OPTIONS"), TAG_IF(sofia_config->sip_t1,NTATAG_SIP_T1(sofia_config->sip_t1)), TAG_IF(sofia_config->sip_t2,NTATAG_SIP_T2(sofia_config->sip_t2)), TAG_IF(sofia_config->sip_t4,NTATAG_SIP_T4(sofia_config->sip_t4)), TAG_IF(sofia_config->sip_t1x64,NTATAG_SIP_T1X64(sofia_config->sip_t1x64)), SIPTAG_USER_AGENT_STR(sofia_config->user_agent_name), TAG_IF(sofia_config->tport_log == TRUE,TPTAG_LOG(1)), /* Print out SIP messages to the console */ TAG_IF(sofia_config->tport_dump_file,TPTAG_DUMP(sofia_config->tport_dump_file)), /* Dump SIP messages to the file */ TAG_END()); /* Last tag should always finish the sequence */ if(!sofia_agent->nua) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create NUA [%s] %s", apt_task_name_get(task), sofia_agent->sip_bind_str); } }
static void mrcp_sofia_task_initialize(apt_task_t *task) { mrcp_sofia_agent_t *sofia_agent = apt_task_object_get(task); /* Initialize Sofia-SIP library and create event loop */ su_init(); sofia_agent->root = su_root_create(NULL); /* Create a user agent instance. The stack will call the 'event_callback()' * callback when events such as succesful registration to network, * an incoming call, etc, occur. */ sofia_agent->nua = nua_create( sofia_agent->root, /* Event loop */ mrcp_sofia_event_callback, /* Callback for processing events */ sofia_agent, /* Additional data to pass to callback */ NUTAG_URL(sofia_agent->sip_bind_str), /* Address to bind to */ TAG_END()); /* Last tag should always finish the sequence */ if(sofia_agent->nua) { nua_set_params( sofia_agent->nua, NUTAG_AUTOANSWER(0), NUTAG_APPL_METHOD("OPTIONS"), SIPTAG_USER_AGENT_STR(sofia_agent->config->user_agent_name), TAG_END()); } }
/** @internal Create a handle for processing incoming request */ nua_handle_t *nua_stack_incoming_handle(nua_t *nua, nta_incoming_t *irq, sip_t const *sip, int create_dialog) { nua_handle_t *nh; url_t const *url; sip_to_t to[1]; sip_from_t from[1]; assert(sip && sip->sip_from && sip->sip_to); if (sip->sip_contact) url = sip->sip_contact->m_url; else url = sip->sip_from->a_url; /* Strip away parameters */ sip_from_init(from)->a_display = sip->sip_to->a_display; *from->a_url = *sip->sip_to->a_url; sip_to_init(to)->a_display = sip->sip_from->a_display; *to->a_url = *sip->sip_from->a_url; nh = nh_create(nua, NUTAG_URL((url_string_t *)url), /* Remote target */ SIPTAG_TO(to), /* Local AoR */ SIPTAG_FROM(from), /* Remote AoR */ TAG_END()); if (nh && nua_stack_init_handle(nua, nh, NULL) < 0) nh_destroy(nua, nh), nh = NULL; if (nh && create_dialog) { struct nua_dialog_state *ds = nh->nh_ds; nua_dialog_store_peer_info(nh, ds, sip); ds->ds_leg = nta_leg_tcreate(nua->nua_nta, nua_stack_process_request, nh, SIPTAG_CALL_ID(sip->sip_call_id), SIPTAG_FROM(sip->sip_to), SIPTAG_TO(sip->sip_from), NTATAG_REMOTE_CSEQ(sip->sip_cseq->cs_seq), TAG_END()); if (!ds->ds_leg || !nta_leg_tag(ds->ds_leg, nta_incoming_tag(irq, NULL))) nh_destroy(nua, nh), nh = NULL; } if (nh) nua_dialog_uas_route(nh, nh->nh_ds, sip, 1); return nh; }
/** * Creates a new operation object and stores it the list of * active operations for 'cli'. */ ssc_oper_t *ssc_oper_create(ssc_t *ssc, sip_method_t method, char const *name, char const *address, tag_type_t tag, tag_value_t value, ...) { ssc_oper_t *op, *old; ta_list ta; enter; for (old = ssc->ssc_operations; old; old = old->op_next) if (!old->op_persistent) break; if (address) { int have_url = 1; sip_to_t *to; to = sip_to_make(ssc->ssc_home, address); if (to == NULL) { printf("%s: %s: invalid address: %s\n", ssc->ssc_name, name, address); return NULL; } /* Try to make sense out of the URL */ if (url_sanitize(to->a_url) < 0) { printf("%s: %s: invalid address\n", ssc->ssc_name, name); return NULL; } if (!(op = su_zalloc(ssc->ssc_home, sizeof(*op)))) { printf("%s: %s: cannot create handle\n", ssc->ssc_name, name); return NULL; } op->op_next = ssc->ssc_operations; op->op_prev_state = -1; op->op_ssc = ssc; ssc->ssc_operations = op; if (method == sip_method_register) have_url = 0; ta_start(ta, tag, value); op->op_handle = nua_handle(ssc->ssc_nua, op, TAG_IF(have_url, NUTAG_URL(to->a_url)), SIPTAG_TO(to), ta_tags(ta)); ta_end(ta); op->op_ident = sip_header_as_string(ssc->ssc_home, (sip_header_t *)to); ssc_oper_assign(op, method, name); if (!op->op_persistent) { ssc_oper_t *old_next; for (; old; old = old_next) { /* Clean old handles */ old_next = old->op_next; if (!old->op_persistent && !old->op_callstate) ssc_oper_destroy(ssc, old); } } su_free(ssc->ssc_home, to); } else if (method || name) ssc_oper_assign(op = old, method, name); else return old; if (!op) { if (address) printf("%s: %s: invalid destination\n", ssc->ssc_name, name); else printf("%s: %s: no destination\n", ssc->ssc_name, name); return NULL; } return op; }
int test_events(struct context *ctx) { BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b; struct call *a_call = a->call, *b_call = b->call; struct event *e, *en, *es; sip_t const *sip; tagi_t const *t, *n_tags, *r_tags; url_t b_url[1]; enum nua_substate substate; nea_sub_t *sub = NULL; char const open[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n" " entity='pres:[email protected]'>\n" " <tuple id='ksac9udshce'>\n" " <status><basic>open</basic></status>\n" " <contact priority='1.0'>sip:[email protected]</contact>\n" " </tuple>\n" "</presence>\n"; char const closed[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n" " entity='pres:[email protected]'>\n" " <tuple id='ksac9udshce'>\n" " <status><basic>closed</basic></status>\n" " </tuple>\n" "</presence>\n"; /* SUBSCRIBE test A B |------SUBSCRIBE---->| |<--------405--------| | | */ if (print_headings) printf("TEST NUA-12.1: SUBSCRIBE without notifier\n"); nua_set_params(b->nua, SIPTAG_ALLOW_EVENTS(NULL), TAG_END()); run_b_until(ctx, nua_r_set_params, until_final_response); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL /* XXX save_until_received */); /* Client events: nua_subscribe(), nua_r_subscribe */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_subscribe); TEST(e->data->e_status, 489); TEST_1(!e->next); #if 0 /* XXX */ /* Server events: nua_i_subscribe */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscribe); TEST(e->data->e_status, 405); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(!e->next); #endif free_events_in_list(ctx, a->events); free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; if (print_headings) printf("TEST NUA-12.1: PASSED\n"); /* ---------------------------------------------------------------------- */ /* SUBSCRIBE test using notifier and establishing subscription A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.2: using notifier and establishing subscription\n"); TEST_1(b_call->nh = nua_handle(b->nua, b_call, TAG_END())); *b_url = *b->contact->m_url; NOTIFIER(b, b_call, b_call->nh, NUTAG_URL(b_url), SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(closed), NEATAG_THROTTLE(1), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), SIPTAG_ACCEPT_STR("application/xpidf, application/pidf+xml"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_received); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); TEST_1(e = es); TEST_E(e->data->e_event, nua_r_subscribe); r_tags = e->data->e_tags; TEST_1(tl_find(r_tags, nutag_substate)); if (es->next == en) { TEST_1(200 <= e->data->e_status && e->data->e_status < 300); TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_embryonic); } else { TEST_1(200 <= e->data->e_status && e->data->e_status < 300); TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_active); } TEST_1(e = en); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* XXX --- Do not check server side events */ free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.2: PASSED\n"); /* ---------------------------------------------------------------------- */ /* NOTIFY with updated content A B | | |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.3: update notifier\n"); /* Update presence data */ NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(open), TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, save_until_received); /* subscriber events: nua_i_notify */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!e->next); free_events_in_list(ctx, a->events); /* XXX --- Do not check server side events */ free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.3: PASSED\n"); /* ---------------------------------------------------------------------- */ /* un-SUBSCRIBE A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.5: un-SUBSCRIBE\n"); memset(&a->flags, 0, sizeof a->flags); UNSUBSCRIBE(a, a_call, a_call->nh, TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_unsubscribe(), nua_i_notify/nua_r_unsubscribe */ TEST_1(e = a->events->head); if (e->data->e_event == nua_i_notify) { TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(e = e->next); TEST_E(e->data->e_event, nua_r_unsubscribe); TEST_1(tl_find(e->data->e_tags, nutag_substate)); TEST(tl_find(e->data->e_tags, nutag_substate)->t_value, nua_substate_terminated); } else { TEST_E(e->data->e_event, nua_r_unsubscribe); TEST_1(tl_find(e->data->e_tags, nutag_substate)); /* NOTIFY is no more dropped after successful response to unsubscribe */ TEST(tl_find(e->data->e_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); } TEST_1(!e->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription with terminated status */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), NUTAG_SUBSTATE_REF(substate), TAG_END()), 2); TEST_1(sub); TEST(substate, nua_substate_terminated); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.5: PASSED\n"); /* ---------------------------------------------------------------------- */ /* Fetch event, SUBSCRIBE with expires: 0 A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.5.1: event fetch\n"); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence"), SIPTAG_ACCEPT_STR("application/pidf+xml"), SIPTAG_EXPIRES_STR("0"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); e = es; TEST_E(e->data->e_event, nua_r_subscribe); TEST_1(t = tl_find(e->data->e_tags, nutag_substate)); TEST_1(t->t_value == nua_substate_pending || t->t_value == nua_substate_terminated || t->t_value == nua_substate_embryonic); e = en; TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/pidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1); TEST_1(sub); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.4.1: PASSED\n"); /* ---------------------------------------------------------------------- */ /* 2nd SUBSCRIBE with event id A B | | |------SUBSCRIBE---->| |<--------202--------| |<------NOTIFY-------| |-------200 OK------>| | | */ /* XXX - we should do this before unsubscribing first one */ if (print_headings) printf("TEST NUA-12.4.2: establishing 2nd subscription\n"); NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"), SIPTAG_PAYLOAD_STR(open), NEATAG_THROTTLE(1), NUTAG_SUBSTATE(nua_substate_pending), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); NOTIFIER(b, b_call, b_call->nh, SIPTAG_EVENT_STR("presence"), SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"), SIPTAG_PAYLOAD_STR(closed), NEATAG_THROTTLE(1), NEATAG_FAKE(1), NUTAG_SUBSTATE(nua_substate_pending), TAG_END()); run_b_until(ctx, nua_r_notifier, until_final_response); SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url), SIPTAG_EVENT_STR("presence;id=1"), SIPTAG_ACCEPT_STR("application/xpidf+xml"), TAG_END()); run_ab_until(ctx, -1, save_until_notified_and_responded, -1, save_until_subscription); /* Client events: nua_subscribe(), nua_i_notify/nua_r_subscribe */ TEST_1(en = event_by_type(a->events->head, nua_i_notify)); TEST_1(es = event_by_type(a->events->head, nua_r_subscribe)); e = es; TEST_E(e->data->e_event, nua_r_subscribe); TEST_1(t = tl_find(e->data->e_tags, nutag_substate)); TEST_1(t->t_value == nua_substate_pending || t->t_value == nua_substate_embryonic); e = en; TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); n_tags = e->data->e_tags; TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_S(sip->sip_event->o_id, "1"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); /* Check that we really got "fake" content */ TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len, "<basic>closed</basic>", strlen("<basic>closed</basic>"))); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "pending"); TEST_1(sip->sip_subscription_state->ss_expires); TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_pending); TEST_1(!en->next || !es->next); free_events_in_list(ctx, a->events); /* Server events: nua_i_subscription */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_subscription); TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1); TEST_1(sub); TEST_1(!e->next); free_events_in_list(ctx, b->events); /* Authorize user A */ AUTHORIZE(b, b_call, b_call->nh, NUTAG_SUBSTATE(nua_substate_active), NEATAG_SUB(sub), NEATAG_FAKE(0), TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, save_until_final_response); /* subscriber events: nua_i_notify with NUTAG_SUBSTATE(nua_substate_active) */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_1(sip->sip_content_type); TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml"); TEST_1(sip->sip_payload && sip->sip_payload->pl_data); /* Check that we really got real content */ TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len, "<basic>open</basic>", strlen("<basic>open</basic>"))); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "active"); TEST_1(sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active); TEST_1(!e->next); free_events_in_list(ctx, a->events); /* Server events: nua_r_authorize */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_authorize); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-12.4: PASSED\n"); /* ---------------------------------------------------------------------- */ /* NOTIFY terminating subscription A B | | |<------NOTIFY-------| |-------200 OK------>| | | */ if (print_headings) printf("TEST NUA-12.6: terminate notifier\n"); TERMINATE(b, b_call, b_call->nh, TAG_END()); run_ab_until(ctx, -1, save_until_notified, -1, until_final_response); /* Client events: nua_i_notify */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence"); TEST_S(sip->sip_event->o_id, "1"); TEST_1(sip->sip_subscription_state); TEST_S(sip->sip_subscription_state->ss_substate, "terminated"); TEST_1(!sip->sip_subscription_state->ss_expires); n_tags = e->data->e_tags; TEST_1(tl_find(n_tags, nutag_substate)); TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated); TEST_1(!e->next); free_events_in_list(ctx, a->events); if (print_headings) printf("TEST NUA-12.6: PASSED\n"); /* ---------------------------------------------------------------------- */ nua_handle_destroy(a_call->nh), a_call->nh = NULL; nua_handle_destroy(b_call->nh), b_call->nh = NULL; END(); /* test_events */ }
END_TEST START_TEST(message_6_4_2) { nua_handle_t *nh; struct message *message; struct event *response; S2_CASE("6.4.2", "MESSAGE with 302/305", "Send MESSAGE"); nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END()); nua_message(nh, SIPTAG_CONTENT_TYPE_STR("text/plain"), SIPTAG_PAYLOAD_STR("hello"), TAG_END()); message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE); s2_sip_respond_to(message, NULL, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR("<sip:[email protected]>"), TAG_END()); s2_sip_free_message(message); response = s2_wait_for_event(nua_r_message, 100); s2_free_event(response); message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE); fail_unless(message->sip->sip_request->rq_url->url_user != NULL); fail_if(strcmp(message->sip->sip_request->rq_url->url_user, "302ed")); s2_sip_respond_to(message, NULL, SIP_305_USE_PROXY, SIPTAG_CONTACT_STR("<sip:[email protected];lr>"), TAG_END()); s2_sip_free_message(message); response = s2_wait_for_event(nua_r_message, 100); s2_free_event(response); message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE); fail_unless(message->sip->sip_route != NULL); fail_unless(message->sip->sip_route->r_url->url_user != NULL); fail_if(strcmp(message->sip->sip_route->r_url->url_user, "routed")); s2_sip_respond_to(message, NULL, SIP_200_OK, TAG_END()); s2_sip_free_message(message); response = s2_wait_for_event(nua_r_message, 200); s2_free_event(response); /* ---------------------------------------------------------------------- */ nua_message(nh, NUTAG_AUTO302(0), SIPTAG_CONTENT_TYPE_STR("text/plain"), SIPTAG_PAYLOAD_STR("hello 2"), TAG_END()); message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE); s2_sip_respond_to(message, NULL, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR("<sip:[email protected]>"), TAG_END()); s2_sip_free_message(message); response = s2_wait_for_event(nua_r_message, 302); fail_unless(response->sip && response->sip->sip_contact); nua_message(nh, NUTAG_URL(response->sip->sip_contact->m_url), NUTAG_AUTO305(0), SIPTAG_CONTENT_TYPE_STR("text/plain"), SIPTAG_PAYLOAD_STR("hello 2"), TAG_END()); s2_free_event(response); message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE); fail_unless(message->sip->sip_request->rq_url->url_user != NULL); fail_if(strcmp(message->sip->sip_request->rq_url->url_user, "not302ed")); s2_sip_respond_to(message, NULL, SIP_305_USE_PROXY, SIPTAG_CONTACT_STR("<sip:[email protected]>"), TAG_END()); s2_sip_free_message(message); response = s2_wait_for_event(nua_r_message, 305); s2_free_event(response); nua_handle_destroy(nh); }
int test_extension(struct context *ctx) { BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b; struct call *a_call = a->call, *b_call = b->call; struct event *e; sip_t const *sip; /* Test for EXTENSION A B |------EXTENSION---->| |<--------501--------| (method not recognized) | | |------EXTENSION---->| |<-------200---------| (method allowed, responded) | | */ if (print_headings) printf("TEST NUA-13.1: EXTENSION\n"); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); /* Test first without NUTAG_METHOD() */ METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 900); /* Internal error */ TEST_1(!e->data->e_msg); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), NUTAG_METHOD("EXTENSION"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 501); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; nua_set_params(b->nua, NUTAG_ALLOW("EXTENSION"), TAG_END()); run_b_until(ctx, nua_r_set_params, until_final_response); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), NUTAG_METHOD("EXTENSION"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, respond_to_extension); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(!e->next); /* Server events: nua_i_method */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_method); TEST(e->data->e_status, 100); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; nua_set_params(b->nua, SIPTAG_ALLOW(b->allow), NUTAG_APPL_METHOD(NULL), NUTAG_APPL_METHOD(b->appl_method), TAG_END()); run_b_until(ctx, nua_r_set_params, until_final_response); if (print_headings) printf("TEST NUA-13.1: PASSED\n"); END(); }