/* Successful SRV query */
static void srv_query(void) {
	int timeout;
	endpoint_t *client = create_endpoint();

	if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
	timeout = belle_sip_stack_get_dns_timeout(client->stack);
	client->resolver_ctx = belle_sip_stack_resolve_srv(client->stack, "udp", SRV_DOMAIN, srv_resolve_done, client);
	BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx);
	BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout));
	BC_ASSERT_PTR_NOT_NULL(client->srv_list);
	BC_ASSERT_NOT_EQUAL(belle_sip_list_size(client->srv_list), 0,int,"%d");
	if (client->srv_list && (belle_sip_list_size(client->srv_list) > 0)) {
		belle_sip_dns_srv_t *result_srv = belle_sip_list_nth_data(client->srv_list, 0);
		BC_ASSERT_EQUAL(belle_sip_dns_srv_get_port(result_srv), SIP_PORT, int, "%d");
	}
示例#2
0
文件: dialog.c 项目: natib/belle-sip
void belle_sip_dialog_delete(belle_sip_dialog_t *obj){
	int dropped_transactions;
	
	belle_sip_dialog_stop_200Ok_retrans(obj); /*if any*/
	set_state(obj,BELLE_SIP_DIALOG_TERMINATED);
	dropped_transactions=belle_sip_list_size(obj->queued_ct);
	if (dropped_transactions>0) belle_sip_warning("dialog [%p]: leaves %i queued transaction aborted.",obj,dropped_transactions);
	belle_sip_list_for_each(obj->queued_ct,(void(*)(void*))belle_sip_transaction_terminate);
	obj->queued_ct=belle_sip_list_free_with_data(obj->queued_ct,belle_sip_object_unref);
	belle_sip_provider_remove_dialog(obj->provider,obj);
}
示例#3
0
void belle_sip_listening_point_clean_channels(belle_sip_listening_point_t *lp){
	int existing_channels;
	belle_sip_list_t* iterator;
	
	if ((existing_channels=belle_sip_list_size(lp->channels)) > 0) {
		belle_sip_message("Listening point destroying [%i] channels",existing_channels);
	}
	for (iterator=lp->channels;iterator!=NULL;iterator=iterator->next) {
		belle_sip_channel_t *chan=(belle_sip_channel_t*)iterator->data;
		belle_sip_channel_force_close(chan);
	}
	lp->channels=belle_sip_list_free_with_data(lp->channels,(void (*)(void*))belle_sip_object_unref);
}
static void cleanup_pool_stack(void *data){
	belle_sip_list_t **pool_stack=(belle_sip_list_t**)data;
	if (*pool_stack){
		/*
		 * We would expect the pool_stack to be empty when the thread terminates.
		 * Otherwise that means the management of object pool is not properly done by the application.
		 * Since the object pools might be still referenced by the application, we can't destroy them.
		 * Instead, we mark them as detached, so that when the thread that will attempt to destroy them will do it,
		 * we'll accept (since anyway these object pool are no longer needed.
		 */
		belle_sip_warning("There were still [%i] object pools for thread [%lu] while the thread exited. ",
				 belle_sip_list_size(*pool_stack),belle_sip_thread_self_id());
		belle_sip_list_free_with_data(*pool_stack,(void (*)(void*)) belle_sip_object_pool_detach_from_thread);
	}
	*pool_stack=NULL;
	belle_sip_free(pool_stack);
}
int belle_sip_object_get_object_count(void){
	return belle_sip_list_size(all_objects);
}
示例#6
0
int belle_sip_listening_point_get_channel_count(const belle_sip_listening_point_t *lp){
	return belle_sip_list_size(lp->channels);
}
示例#7
0
if (!check_component(uri_component,component_use_rule)) {\
	belle_sip_error("Uri component [%s] does not follow reqs [%s] for context [%s]", uri_component_name,mark_to_string(component_use_rule),component_use_rule_name);\
	return FALSE;\
}

static int check_uri_components(const belle_sip_uri_t* uri,  const uri_components_t* components_use) {

	CHECK_URI_COMPONENT(uri->user!=NULL,"user",components_use->user,components_use->name)
	CHECK_URI_COMPONENT(uri->host!=NULL,"host",components_use->host,components_use->name)
	CHECK_URI_COMPONENT(uri->port>0,"port",components_use->port,components_use->name)
	CHECK_URI_COMPONENT(belle_sip_parameters_has_parameter(&uri->params,"maddr"),"maddr-param",components_use->maddr_param,components_use->name)
	CHECK_URI_COMPONENT(belle_sip_parameters_has_parameter(&uri->params,"ttl"),"ttl-param",components_use->ttl_param,components_use->name)
	CHECK_URI_COMPONENT(belle_sip_parameters_has_parameter(&uri->params,"transport"),"transp.-param",components_use->transp_param,components_use->name)
	CHECK_URI_COMPONENT(belle_sip_parameters_has_parameter(&uri->params,"lr"),"lr-param",components_use->lr_param,components_use->name)
	/*..*/
	CHECK_URI_COMPONENT(belle_sip_list_size(belle_sip_parameters_get_parameters(uri->header_list))>0,"headers",components_use->headers,components_use->name)
	return TRUE;
}

/*return 0 if not compliant*/
int belle_sip_uri_check_components_from_request_uri(const belle_sip_uri_t* uri) {
	return check_uri_components(uri,&uri_component_use_for_request);
}
int belle_sip_uri_check_components_from_context(const belle_sip_uri_t* uri,const char* method,const char* header_name) {

	if (strcasecmp(BELLE_SIP_FROM,header_name)==0)
		return check_uri_components(uri,&uri_component_use_for_header_from);
	else if (strcasecmp(BELLE_SIP_TO,header_name)==0)
		return check_uri_components(uri,&uri_component_use_for_header_to);
	else if (strcasecmp(BELLE_SIP_CONTACT,header_name)==0 && method && strcasecmp("REGISTER",method)==0)
		return check_uri_components(uri,&uri_component_use_for_contact_in_reg);
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);
	}
}