Ejemplo n.º 1
0
static belle_sip_request_t *_belle_sip_dialog_create_request_from(belle_sip_dialog_t *obj, const belle_sip_request_t *initial_req, int queued){
	belle_sip_request_t* req;
	const char *method=belle_sip_request_get_method(initial_req);
	belle_sip_header_content_length_t* content_lenth;
	belle_sip_list_t* headers;
	
	if (queued) req=belle_sip_dialog_create_queued_request(obj,method);
	else req=belle_sip_dialog_create_request(obj,method);
	
	if (req==NULL) return NULL;
	
	content_lenth = belle_sip_message_get_header_by_type(initial_req,belle_sip_header_content_length_t);
	/*first copy non system headers*/
	headers = belle_sip_message_get_all_headers(BELLE_SIP_MESSAGE(initial_req));
	belle_sip_list_for_each2(headers,(void (*)(void *, void *))copy_non_system_headers,req);
	belle_sip_list_free(headers);
	
	/*replicate via user parameters, if any, useful for 'alias' parameter in SUBSCRIBE requests*/
	{
		belle_sip_header_via_t *orig_via=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(initial_req),belle_sip_header_via_t);
		belle_sip_header_via_t *new_via=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_via_t);
		belle_sip_parameters_copy_parameters_from(BELLE_SIP_PARAMETERS(new_via),BELLE_SIP_PARAMETERS(orig_via));
	}
	
	/*copy body*/
	if (content_lenth && belle_sip_header_content_length_get_content_length(content_lenth)>0) {
		belle_sip_message_set_body(BELLE_SIP_MESSAGE(req),belle_sip_message_get_body(BELLE_SIP_MESSAGE(initial_req)),belle_sip_header_content_length_get_content_length(content_lenth));
	}
	return req;
}
Ejemplo n.º 2
0
int sal_unlisten_ports(Sal *ctx){
	const belle_sip_list_t * lps = belle_sip_provider_get_listening_points(ctx->prov);
	belle_sip_list_t * tmp_list = belle_sip_list_copy(lps);
	belle_sip_list_for_each2 (tmp_list,(void (*)(void*,void*))remove_listening_point,ctx->prov);
	belle_sip_list_free(tmp_list);
	ms_message("sal_unlisten_ports done");
	return 0;
}
Ejemplo n.º 3
0
void belle_http_provider_cancel_request(belle_http_provider_t *obj, belle_http_request_t *req){
	belle_sip_list_t *outgoing_messages;

	belle_http_request_cancel(req);
	if (req->channel){
		// Keep the list of the outgoing messages of the channel...
		outgoing_messages = belle_sip_list_copy_with_data(req->channel->outgoing_messages,(void* (*)(void*))belle_sip_object_ref);
		provider_remove_channel(obj, req->channel);
		// ... close the channel...
		belle_sip_channel_force_close(req->channel);
		// ... and reenqueue the previously queued outgoing messages into a new channel
		belle_sip_list_for_each2(outgoing_messages,(void (*)(void*,void*))reenqueue_request,obj);
		belle_sip_list_free_with_data(outgoing_messages,belle_sip_object_unref);
	}
}
Ejemplo n.º 4
0
void belle_sip_object_data_foreach( const belle_sip_object_t* obj, void (*apply_func)(const char* key, void* data, void* userdata), void* userdata)
{
	struct belle_sip_object_foreach_data fd = { apply_func, userdata };
	belle_sip_list_for_each2(obj->data_store, belle_sip_object_for_each_cb, &fd);
}
Ejemplo n.º 5
0
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, size_t *offset) {
	const belle_sip_list_t* list;
	belle_sip_error_code error=BELLE_SIP_OK;

	error=belle_sip_snprintf(buff,buff_size,offset,"%s:",uri->secure?"sips":"sip");
	if (error!=BELLE_SIP_OK) return error;

	if (uri->user && uri->user[0]!='\0') {
		char* escaped_username=belle_sip_uri_to_escaped_username(uri->user);
		error=belle_sip_snprintf(buff,buff_size,offset,"%s",escaped_username);
		belle_sip_free(escaped_username);
		if (error!=BELLE_SIP_OK) return error;

		if (uri->user_password) {
			char* escaped_password=belle_sip_uri_to_escaped_userpasswd(uri->user_password);
			error=belle_sip_snprintf(buff,buff_size,offset,":%s",escaped_password);
			belle_sip_free(escaped_password);
			if (error!=BELLE_SIP_OK) return error;
		}
		error=belle_sip_snprintf(buff,buff_size,offset,"@");
		if (error!=BELLE_SIP_OK) return error;

	}

	if (uri->host) {
		if (strchr(uri->host,':')) { /*ipv6*/
			error=belle_sip_snprintf(buff,buff_size,offset,"[%s]",uri->host);
		} else {
			error=belle_sip_snprintf(buff,buff_size,offset,"%s",uri->host);
		}
		if (error!=BELLE_SIP_OK) return error;
	} else {
		belle_sip_warning("no host found in this uri");
	}

	if (uri->port!=0) {
		error=belle_sip_snprintf(buff,buff_size,offset,":%i",uri->port);
		if (error!=BELLE_SIP_OK) return error;
	}

	{
		belle_sip_parameters_t *encparams = belle_sip_parameters_new();
		belle_sip_list_for_each2(uri->params.param_list, (void (*)(void *, void *))encode_params, &encparams->param_list);
		error=belle_sip_parameters_marshal(encparams,buff,buff_size,offset);
		belle_sip_parameters_destroy(encparams);
		if (error!=BELLE_SIP_OK) return error;
	}

	{
		belle_sip_list_t * encheaders = NULL;
		belle_sip_list_for_each2(uri->header_list->param_list, (void (*)(void *, void *))encode_headers, &encheaders);

		for(list=encheaders;list!=NULL;list=list->next){
			belle_sip_param_pair_t* container = list->data;
			if (list == encheaders) {
				//first case
				error=belle_sip_snprintf(buff,buff_size,offset,"?%s=%s",container->name,container->value?container->value:"");
			} else {
				//subsequent headers
				error=belle_sip_snprintf(buff,buff_size,offset,"&%s=%s",container->name,container->value?container->value:"");
			}
			if (error!=BELLE_SIP_OK) break;
		}
		belle_sip_list_free_with_data(encheaders,(void (*)(void*))belle_sip_param_pair_destroy);
	}

	return error;
}