Пример #1
0
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction) {
	belle_sip_refresher_t* refresher;
	belle_sip_transaction_state_t state=belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(transaction));
	belle_sip_request_t* request = belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(transaction));
	int is_register=strcmp("REGISTER",belle_sip_request_get_method(request))==0;

	refresher = (belle_sip_refresher_t*)belle_sip_object_new(belle_sip_refresher_t);
	refresher->transaction=transaction;
	refresher->state=stopped;
	refresher->number_of_retry=0;
	belle_sip_object_ref(transaction);
	refresher->retry_after=DEFAULT_RETRY_AFTER;

	if (belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(transaction))) {
		set_or_update_dialog(refresher, belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(transaction)));
	}
	belle_sip_provider_add_internal_sip_listener(transaction->base.provider,BELLE_SIP_LISTENER(refresher), is_register);
	if (set_expires_from_trans(refresher)==-1){
		belle_sip_error("Unable to extract refresh value from transaction [%p]",transaction);
	}
	if (belle_sip_transaction_state_is_transient(state)) {
		belle_sip_message("Refresher [%p] takes ownership of transaction [%p]",refresher,transaction);
		transaction->base.is_internal=1;
		refresher->state=started;
	}else{
		belle_sip_refresher_start(refresher);
	}
	return refresher;
}
Пример #2
0
belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
	,belle_sip_provider_t *prov
	,const char *transport
	,int use_transaction
	,const char* username
	,const char* domain
	,const char* outbound_proxy
	,int success_expected) {
	belle_sip_request_t *req,*copy;
	char identity[256];
	char uri[256];
	int i;
	char *outbound=NULL;

	number_of_challenge=0;
	if (transport)
		snprintf(uri,sizeof(uri),"sip:%s;transport=%s",domain,transport);
	else snprintf(uri,sizeof(uri),"sip:%s",domain);

	if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
		belle_sip_error("No TLS support, test skipped.");
		return NULL;
	}

	if (outbound_proxy){
		if (strstr(outbound_proxy,"sip:")==NULL && strstr(outbound_proxy,"sips:")==NULL){
			outbound=belle_sip_strdup_printf("sip:%s",outbound_proxy);
		}else outbound=belle_sip_strdup(outbound_proxy);
	}

	snprintf(identity,sizeof(identity),"Tester <sip:%s@%s>",username,domain);
	req=belle_sip_request_create(
						belle_sip_uri_parse(uri),
						"REGISTER",
						belle_sip_provider_create_call_id(prov),
						belle_sip_header_cseq_create(20,"REGISTER"),
						belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
						belle_sip_header_to_create2(identity,NULL),
						belle_sip_header_via_new(),
						70);
	is_register_ok=0;
	io_error_count=0;
	using_transaction=0;
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(600)));
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_contact_new()));
	copy=(belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)req));
	belle_sip_provider_add_sip_listener(prov,l=BELLE_SIP_LISTENER(listener));
	if (use_transaction){
		belle_sip_client_transaction_t *t=belle_sip_provider_create_client_transaction(prov,req);
		belle_sip_client_transaction_send_request_to(t,outbound?belle_sip_uri_parse(outbound):NULL);
	}else belle_sip_provider_send_request(prov,req);
	for(i=0;!is_register_ok && i<2 && io_error_count==0;i++)
		belle_sip_stack_sleep(stack,5000);
	CU_ASSERT_EQUAL(is_register_ok,success_expected);
	if (success_expected) CU_ASSERT_EQUAL(using_transaction,use_transaction);

	belle_sip_provider_remove_sip_listener(prov,l);
	if (outbound) belle_sip_free(outbound);
	return copy;
}
Пример #3
0
static void destroy(belle_sip_refresher_t *refresher){
	belle_sip_refresher_stop(refresher);
	belle_sip_provider_remove_internal_sip_listener(refresher->transaction->base.provider,BELLE_SIP_LISTENER(refresher));
	belle_sip_object_unref(refresher->transaction);
	refresher->transaction=NULL;
	if (refresher->realm) belle_sip_free(refresher->realm);
	if (refresher->auth_events) refresher->auth_events=belle_sip_list_free_with_data(refresher->auth_events,(void (*)(void*))belle_sip_auth_event_destroy);
	if (refresher->first_acknoleged_request) belle_sip_object_unref(refresher->first_acknoleged_request);
	if (refresher->dialog) belle_sip_object_unref(refresher->dialog);
}
Пример #4
0
static void reuse_nonce(void) {
	belle_sip_request_t *register_request;
	int initial_auth_context_count=belle_sip_list_size(prov->auth_contexts);
	register_request=register_user_at_domain(stack, prov, "tcp",1,"marie","sip.linphone.org",NULL);
	if (register_request) {

		char * first_nonce_used;
		belle_sip_header_authorization_t * h = NULL;
		belle_sip_request_t *message_request;
		listener_callbacks.process_dialog_terminated=process_dialog_terminated;
		listener_callbacks.process_io_error=process_io_error;
		listener_callbacks.process_request_event=process_request_event;
		listener_callbacks.process_response_event=process_message_response_event;
		listener_callbacks.process_timeout=process_timeout;
		listener_callbacks.process_transaction_terminated=process_transaction_terminated;
		listener_callbacks.process_auth_requested=process_auth_requested;
		listener_callbacks.listener_destroyed=NULL;
		listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,NULL);

		belle_sip_provider_add_sip_listener(prov,BELLE_SIP_LISTENER(listener));

		/*currently only one nonce should have been used (the one for the REGISTER)*/
		CU_ASSERT_EQUAL(belle_sip_list_size(prov->auth_contexts), initial_auth_context_count+1);

		/*this should reuse previous nonce*/
		message_request=send_message(register_request, auth_domain);
		CU_ASSERT_EQUAL(is_register_ok, 404);
		 h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
					BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
				));
		CU_ASSERT_PTR_NOT_NULL_FATAL(h);
		CU_ASSERT_EQUAL(2, belle_sip_header_authorization_get_nonce_count(h));
		first_nonce_used = belle_sip_strdup(belle_sip_header_authorization_get_nonce(h));

		belle_sip_object_unref(message_request);


		/*new nonce should be created when not using outbound proxy realm*/
		message_request=send_message(register_request, NULL);
		CU_ASSERT_EQUAL(is_register_ok, 407);
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
		CU_ASSERT_PTR_NULL_FATAL(h);
		belle_sip_object_unref(message_request);


		/*new nonce should be created here too*/
		message_request=send_message(register_request, "wrongrealm");
		CU_ASSERT_EQUAL(is_register_ok, 407);
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
		CU_ASSERT_PTR_NULL_FATAL(h);
		belle_sip_object_unref(message_request);


		/*first nonce created should be reused*/
		message_request=send_message(register_request, auth_domain);
		CU_ASSERT_EQUAL(is_register_ok, 404);
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
		CU_ASSERT_PTR_NOT_NULL_FATAL(h);
		CU_ASSERT_EQUAL(3, belle_sip_header_authorization_get_nonce_count(h));
		belle_sip_object_unref(message_request);

		belle_sip_provider_remove_sip_listener(prov,BELLE_SIP_LISTENER(listener));
		unregister_user(stack,prov,register_request,1);
		belle_sip_object_unref(register_request);
		belle_sip_free(first_nonce_used);
	}
}