belle_sip_header_contact_t* sal_op_create_contact(SalOp *op){ belle_sip_header_contact_t* contact_header; belle_sip_uri_t* contact_uri; if (sal_op_get_contact_address(op)) { contact_header = belle_sip_header_contact_create(BELLE_SIP_HEADER_ADDRESS(sal_op_get_contact_address(op))); } else { contact_header= belle_sip_header_contact_new(); } if (!(contact_uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact_header)))) { /*no uri, just creating a new one*/ contact_uri=belle_sip_uri_new(); belle_sip_header_address_set_uri(BELLE_SIP_HEADER_ADDRESS(contact_header),contact_uri); } belle_sip_uri_set_user_password(contact_uri,NULL); belle_sip_uri_set_secure(contact_uri,sal_op_is_secure(op)); if (op->privacy!=SalPrivacyNone){ belle_sip_uri_set_user(contact_uri,NULL); } belle_sip_header_contact_set_automatic(contact_header,op->base.root->auto_contacts); if (op->base.root->uuid){ if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance")==0){ char *instance_id=belle_sip_strdup_printf("\"<urn:uuid:%s>\"",op->base.root->uuid); belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(contact_header),"+sip.instance",instance_id); belle_sip_free(instance_id); } } return contact_header; }
belle_sip_request_t* build_request(belle_sip_stack_t * stack , belle_sip_provider_t *prov ,belle_sip_header_address_t* from ,belle_sip_header_address_t* to ,belle_sip_header_address_t* route ,const char* method) { belle_sip_header_from_t* from_header; belle_sip_header_to_t* to_header; belle_sip_request_t *req; belle_sip_uri_t* req_uri; belle_sip_header_contact_t* contact_header; BELLESIP_UNUSED(stack); from_header = belle_sip_header_from_create(from,BELLE_SIP_RANDOM_TAG); to_header = belle_sip_header_to_create(to,NULL); req_uri = (belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_header_address_get_uri((belle_sip_header_address_t*)to_header)); contact_header= belle_sip_header_contact_new(); belle_sip_header_address_set_uri((belle_sip_header_address_t*)contact_header,belle_sip_uri_new()); belle_sip_uri_set_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)contact_header),belle_sip_uri_get_user(req_uri)); req=belle_sip_request_create( req_uri, method, belle_sip_provider_create_call_id(prov), belle_sip_header_cseq_create(20,method), from_header, to_header, belle_sip_header_via_new(), 70); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact_header)); if (route) { belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_route_create(route))); } return req; }
/* Address manipulation API*/ SalAddress * sal_address_new(const char *uri){ belle_sip_header_address_t* result; if (uri) { result=belle_sip_header_address_parse (uri); /*may return NULL*/ } else { result = belle_sip_header_address_new(); belle_sip_header_address_set_uri(result,belle_sip_uri_new()); } if (result) belle_sip_object_ref(result); return (SalAddress *)result; }
belle_sip_uri_t *belle_sip_channel_create_routable_uri(belle_sip_channel_t *chan) { const char *transport = belle_sip_channel_get_transport_name_lower_case(chan); belle_sip_uri_t* uri = belle_sip_uri_new(); unsigned char natted = chan->public_ip && strcmp(chan->public_ip,chan->local_ip)!=0; if (natted) { belle_sip_uri_set_host(uri, chan->public_ip); belle_sip_uri_set_port(uri, chan->public_port); } else { belle_sip_uri_set_host(uri, chan->local_ip); // With streamed protocols listening port is what we want if (chan->lp) belle_sip_uri_set_port(uri, belle_sip_uri_get_port(chan->lp->listening_uri)); else belle_sip_uri_set_port(uri,chan->local_port); } belle_sip_uri_set_transport_param(uri, transport); belle_sip_uri_set_lr_param(uri, TRUE); return uri; }
belle_sip_uri_t* belle_sip_uri_create (const char* username,const char* host) { belle_sip_uri_t* uri = belle_sip_uri_new(); belle_sip_uri_set_user(uri,username); belle_sip_uri_set_host(uri,host); return uri; }