void linphone_nat_policy_set_stun_server(LinphoneNatPolicy *policy, const char *stun_server) { char *new_stun_server = NULL; if (stun_server != NULL) new_stun_server = belle_sip_strdup(stun_server); if (policy->stun_server != NULL) { belle_sip_free(policy->stun_server); policy->stun_server = NULL; } if (new_stun_server != NULL) { policy->stun_server = new_stun_server; linphone_nat_policy_resolve_stun_server(policy); } }
int belle_sip_tls_listening_point_set_root_ca(belle_sip_tls_listening_point_t *lp, const char *path){ if (lp->root_ca){ belle_sip_free(lp->root_ca); lp->root_ca=NULL; } if (path){ lp->root_ca=belle_sip_strdup(path); belle_sip_message("Root ca path set to %s",lp->root_ca); } else { belle_sip_message("Root ca path disabled"); } return 0; }
static void test_escaped_username(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:toto%[email protected]"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "*****@*****.**"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
int sal_call_refer_to(SalOp *op, belle_sip_header_refer_to_t* refer_to, belle_sip_header_referred_by_t* referred_by){ char* tmp; belle_sip_request_t* req=op->dialog?belle_sip_dialog_create_request(op->dialog,"REFER"):sal_op_build_request(op, "REFER"); if (!req) { tmp=belle_sip_uri_to_string(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(refer_to))); ms_error("Cannot refer to [%s] for op [%p]",tmp,op); belle_sip_free(tmp); return -1; } belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(refer_to)); if (referred_by) belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(referred_by)); return sal_op_send_request(op,req); }
static void testSIPSURI(void) { belle_sip_uri_t * L_uri = belle_sip_uri_parse("sips:linphone.org"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_uri = belle_sip_uri_parse(l_raw_uri); belle_sip_free(l_raw_uri); CU_ASSERT_EQUAL(belle_sip_uri_is_secure(L_uri), 1); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_uri = belle_sip_uri_parse("sip:linphone.org"); CU_ASSERT_EQUAL(belle_sip_uri_is_secure(L_uri), 0); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
void belle_sip_object_delete(void *ptr){ belle_sip_object_t *obj=BELLE_SIP_OBJECT(ptr); belle_sip_object_vptr_t *vptr; belle_sip_object_loose_weak_refs(obj); vptr=obj->vptr; while(vptr!=NULL){ if (vptr->destroy) vptr->destroy(obj); vptr=vptr->get_parent(); } belle_sip_object_data_clear(obj); belle_sip_free(obj); }
static void test_escaped_parameter(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:[email protected];pa%3Dram=aa%40bb:5060[];o%40"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_uri), "pa=ram"), "aa@bb:5060[]"); CU_ASSERT_TRUE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri), "o@")); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void tls_channel_uninit(belle_sip_tls_channel_t *obj){ belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj); if (sock!=(belle_sip_socket_t)-1) tls_channel_close(obj); ssl_free(&obj->sslctx); #if POLARSSL_VERSION_NUMBER < 0x01030000 x509_free(&obj->root_ca); #else x509_crt_free(&obj->root_ca); #endif if (obj->cur_debug_msg) belle_sip_free(obj->cur_debug_msg); belle_sip_object_unref(obj->verify_ctx); }
static void test_origin(void) { belle_sdp_origin_t* lTmp; belle_sdp_origin_t* lOrigin = belle_sdp_origin_parse("o=jehan-mac 3800 2558 IN IP4 192.168.0.165"); char* l_raw_origin = belle_sip_object_to_string(BELLE_SIP_OBJECT(lOrigin)); belle_sip_object_unref(BELLE_SIP_OBJECT(lOrigin)); lTmp = belle_sdp_origin_parse(l_raw_origin); lOrigin = BELLE_SDP_ORIGIN(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(lOrigin), "192.168.0.165"); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(lOrigin), "IP4"); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(lOrigin), "IN"); belle_sip_object_unref(BELLE_SIP_OBJECT(lOrigin)); belle_sip_free(l_raw_origin); }
static char * belle_sip_object_to_alloc_string(belle_sip_object_t *obj, int size_hint){ char *buf=belle_sip_malloc(size_hint); size_t offset=0; belle_sip_error_code error = belle_sip_object_marshal(obj,buf,size_hint-1,&offset); obj->vptr->tostring_bufsize_hint=size_hint; if (error==BELLE_SIP_BUFFER_OVERFLOW){ belle_sip_message("belle_sip_object_to_alloc_string(): hint buffer was too short while doing to_string() for %s, retrying", obj->vptr->type_name); belle_sip_free(buf); return belle_sip_object_to_alloc_string(obj,2*size_hint); } buf=belle_sip_realloc(buf,offset+1); buf[offset]='\0'; return buf; }
static void test_connection_6(void) { belle_sdp_connection_t* lTmp; belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP6 2a01:e35:1387:1020:6233:4bff:fe0b:5663"); char* l_raw_connection = belle_sip_object_to_string(BELLE_SIP_OBJECT(lConnection)); belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection)); lTmp = belle_sdp_connection_parse(l_raw_connection); lConnection = BELLE_SDP_CONNECTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address(lConnection), "2a01:e35:1387:1020:6233:4bff:fe0b:5663"); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address_type(lConnection), "IP6"); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_network_type(lConnection), "IN"); belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection)); belle_sip_free(l_raw_connection); }
static void testSIMPLEURI(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t* L_uri = belle_sip_uri_parse("sip:sip.titi.com"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri)); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.titi.com"); CU_ASSERT_PTR_NULL(belle_sip_uri_get_transport_param(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void testCOMPLEXURI(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:[email protected]:5060;transport=tcp"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "toto"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(L_uri), "tcp"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void belle_sip_channel_destroy(belle_sip_channel_t *obj){ if (obj->peer_list) belle_sip_freeaddrinfo(obj->peer_list); if (obj->peer_cname) belle_sip_free(obj->peer_cname); belle_sip_free(obj->peer_name); if (obj->local_ip) belle_sip_free(obj->local_ip); obj->listeners=for_each_weak_unref_free(obj->listeners,(belle_sip_object_destroy_notify_t)channel_remove_listener,obj); if (obj->resolver_ctx>0) belle_sip_resolver_context_cancel(obj->resolver_ctx); if (obj->inactivity_timer){ belle_sip_main_loop_remove_source(obj->stack->ml,obj->inactivity_timer); belle_sip_object_unref(obj->inactivity_timer); } if (obj->public_ip) belle_sip_free(obj->public_ip); if (obj->outgoing_messages) belle_sip_list_free_with_data(obj->outgoing_messages,belle_sip_object_unref); free_ewouldblock_buffer(obj); if (obj->cur_out_message){ belle_sip_object_unref(obj->cur_out_message); obj->cur_out_message=NULL; } channel_end_send_background_task(obj); channel_end_recv_background_task(obj); /*normally this should do nothing because it sould have been terminated already, however leaving a background task open is so dangerous that we have to be paranoid*/ belle_sip_message("Channel [%p] destroyed",obj); }
static int send_buffer(belle_sip_channel_t *obj, const char *buffer, size_t size){ int ret=0; char *logbuf=NULL; if (obj->stack->send_error == 0){ ret=belle_sip_channel_send(obj,buffer,size); }else if (obj->stack->send_error<0){ /*for testing purpose only */ ret=obj->stack->send_error; } else { ret=size; /*to silently discard message*/ } if (ret<0){ if (!belle_sip_error_code_is_would_block(-ret)){ belle_sip_error("channel [%p]: could not send [%i] bytes from [%s://%s:%i] to [%s:%i]" ,obj ,(int)size ,belle_sip_channel_get_transport_name(obj) ,obj->local_ip ,obj->local_port ,obj->peer_name ,obj->peer_port); channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR); }/*ewouldblock error has to be handled by caller*/ }else if (size==(size_t)ret){ logbuf=make_logbuf(BELLE_SIP_LOG_MESSAGE, buffer,size); belle_sip_message("channel [%p]: message %s to [%s://%s:%i], size: [%i] bytes\n%s" ,obj ,obj->stack->send_error==0?"sent":"silently discarded" ,belle_sip_channel_get_transport_name(obj) ,obj->peer_name ,obj->peer_port ,ret ,logbuf); }else{ logbuf=make_logbuf(BELLE_SIP_LOG_MESSAGE,buffer,ret); belle_sip_message("channel [%p]: message partly sent to [%s://%s:%i], sent: [%i/%i] bytes:\n%s" ,obj ,belle_sip_channel_get_transport_name(obj) ,obj->peer_name ,obj->peer_port ,ret ,(int)size ,logbuf); } if (logbuf) belle_sip_free(logbuf); return ret; }
static void test_connection(void) { belle_sdp_connection_t* lTmp; belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18"); char* l_raw_connection = belle_sip_object_to_string(BELLE_SIP_OBJECT(lConnection)); belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection)); lTmp = belle_sdp_connection_parse(l_raw_connection); lConnection = BELLE_SDP_CONNECTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address(lConnection), "192.168.0.18"); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_address_type(lConnection), "IP4"); CU_ASSERT_STRING_EQUAL(belle_sdp_connection_get_network_type(lConnection), "IN"); CU_ASSERT_EQUAL(belle_sdp_connection_get_ttl(lConnection), 0); CU_ASSERT_EQUAL(belle_sdp_connection_get_ttl(lConnection), 0); belle_sip_object_unref(BELLE_SIP_OBJECT(lConnection)); belle_sip_free(l_raw_connection); }
static void test_escaped_passwd(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sips:%22jehan%22%20%3cjehan%40sip2.linphone.org:544%[email protected]"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "\"jehan\" <*****@*****.**"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user_password(L_uri), "544>"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static int belle_sip_channel_process_read_data(belle_sip_channel_t *obj){ int num; int ret=BELLE_SIP_CONTINUE; /*prevent system to suspend the process until we have finish reading everything from the socket and notified the upper layer*/ if (obj->input_stream.state == WAITING_MESSAGE_START) channel_begin_recv_background_task(obj); if (obj->simulated_recv_return>0) { num=belle_sip_channel_recv(obj,obj->input_stream.write_ptr,belle_sip_channel_input_stream_get_buff_length(&obj->input_stream)-1); } else { belle_sip_message("channel [%p]: simulating recv() returning %i",obj,obj->simulated_recv_return); num=obj->simulated_recv_return; } if (num>0){ char *begin=obj->input_stream.write_ptr; char *logbuf=make_logbuf(BELLE_SIP_LOG_MESSAGE,begin,num); obj->input_stream.write_ptr+=num; /*first null terminate the read buff*/ *obj->input_stream.write_ptr='\0'; if (num>20) /*to avoid tracing server based keep alives*/ belle_sip_message("channel [%p]: received [%i] new bytes from [%s://%s:%i]:\n%s", obj, num, belle_sip_channel_get_transport_name(obj), obj->peer_name, obj->peer_port, logbuf); belle_sip_free(logbuf); belle_sip_channel_process_stream(obj,FALSE); } else if (num == 0) { /*before closing the channel, check if there was a pending message to receive, whose body acquisition is to be finished.*/ belle_sip_channel_process_stream(obj,TRUE); channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED); ret=BELLE_SIP_STOP; } else if (belle_sip_error_code_is_would_block(-num)){ belle_sip_message("channel [%p]: recv() EWOULDBLOCK",obj); ret=BELLE_SIP_CONTINUE; }else{ belle_sip_error("Receive error on channel [%p]",obj); channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR); ret=BELLE_SIP_STOP; } if (obj->input_stream.state == WAITING_MESSAGE_START) channel_end_recv_background_task(obj); return ret; }
int sal_call_refer_with_replaces(SalOp *op, SalOp *other_call_op){ belle_sip_dialog_state_t other_call_dialog_state=other_call_op->dialog?belle_sip_dialog_get_state(other_call_op->dialog):BELLE_SIP_DIALOG_NULL; belle_sip_dialog_state_t op_dialog_state=op->dialog?belle_sip_dialog_get_state(op->dialog):BELLE_SIP_DIALOG_NULL; belle_sip_header_replaces_t* replaces; belle_sip_header_refer_to_t* refer_to; belle_sip_header_referred_by_t* referred_by; const char* from_tag; const char* to_tag; char* escaped_replaces; /*first, build refer to*/ if ((other_call_dialog_state!=BELLE_SIP_DIALOG_CONFIRMED) && (other_call_dialog_state!=BELLE_SIP_DIALOG_EARLY)) { ms_error("wrong dialog state [%s] for op [%p], should be BELLE_SIP_DIALOG_CONFIRMED or BELE_SIP_DIALOG_EARLY", belle_sip_dialog_state_to_string(other_call_dialog_state), other_call_op); return -1; } if (op_dialog_state!=BELLE_SIP_DIALOG_CONFIRMED) { ms_error("wrong dialog state [%s] for op [%p], should be BELLE_SIP_DIALOG_CONFIRMED", belle_sip_dialog_state_to_string(op_dialog_state), op); return -1; } refer_to=belle_sip_header_refer_to_create(belle_sip_dialog_get_remote_party(other_call_op->dialog)); belle_sip_parameters_clean(BELLE_SIP_PARAMETERS(refer_to)); /*rfc3891 ... 4. User Agent Client Behavior: Sending a Replaces Header A User Agent that wishes to replace a single existing early or confirmed dialog with a new dialog of its own, MAY send the target User Agent an INVITE request containing a Replaces header field. The User Agent Client (UAC) places the Call-ID, to-tag, and from-tag information for the target dialog in a single Replaces header field and sends the new INVITE to the target.*/ from_tag=belle_sip_dialog_get_local_tag(other_call_op->dialog); to_tag=belle_sip_dialog_get_remote_tag(other_call_op->dialog); replaces=belle_sip_header_replaces_create(belle_sip_header_call_id_get_call_id(belle_sip_dialog_get_call_id(other_call_op->dialog)) ,from_tag,to_tag); escaped_replaces=belle_sip_header_replaces_value_to_escaped_string(replaces); belle_sip_uri_set_header(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(refer_to)),"Replaces",escaped_replaces); belle_sip_free(escaped_replaces); referred_by=belle_sip_header_referred_by_create(belle_sip_dialog_get_local_party(op->dialog)); belle_sip_parameters_clean(BELLE_SIP_PARAMETERS(referred_by)); return sal_call_refer_to(op,refer_to,referred_by); }
void belle_sip_listening_point_init(belle_sip_listening_point_t *lp, belle_sip_stack_t *s, const char *address, int port){ char *tmp; belle_sip_init_sockets(); lp->stack=s; lp->listening_uri=belle_sip_uri_create(NULL,address); belle_sip_object_ref(lp->listening_uri); belle_sip_uri_set_port(lp->listening_uri,port); belle_sip_uri_set_transport_param(lp->listening_uri,BELLE_SIP_OBJECT_VPTR(lp,belle_sip_listening_point_t)->transport); tmp=belle_sip_object_to_string((belle_sip_object_t*)BELLE_SIP_LISTENING_POINT(lp)->listening_uri); if (strchr(address,':')) { lp->ai_family=AF_INET6; } else { lp->ai_family=AF_INET; } belle_sip_message("Creating listening point [%p] on [%s]",lp, tmp); belle_sip_free(tmp); }
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); }
static void testHttp200Ok(void) { const char* raw_message = "HTTP/1.1 200 OK\r\n" "Date: Tue, 07 Jan 2014 09:28:43 GMT\r\n" "Server: Apache\r\n" "Last-Modified: Tue, 18 Aug 1998 20:19:11 GMT\r\n" "ETag: \"8982a60-14a17-335b3dcdcadc0\"\r\n" "Accept-Ranges: bytes\r\n" "Vary: Accept-Encoding\r\n" "Content-Encoding: gzip\r\n" "Content-Length: 6\r\n" "Keep-Alive: timeout=15, max=100\r\n" "Connection: Keep-Alive\r\n" "Content-Type: text/plain\r\n" "\r\n" "blabla"; char* marshaled_msg; belle_sip_message_t* msg = belle_sip_message_parse(raw_message); belle_http_response_t* http_response; belle_sip_header_extension_t* host_header; belle_sip_object_t* tmp; CU_ASSERT_PTR_NOT_NULL_FATAL(msg); marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg = belle_sip_message_parse(marshaled_msg); belle_sip_free(marshaled_msg); tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg=BELLE_SIP_MESSAGE(tmp); CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_response_t)); http_response=BELLE_HTTP_RESPONSE(msg); CU_ASSERT_EQUAL(belle_http_response_get_status_code(http_response),200); CU_ASSERT_STRING_EQUAL(belle_http_response_get_reason_phrase(http_response),"OK"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Date")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"ETag")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection")); CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Server"))); CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"Apache"); belle_sip_object_unref(msg); }
void belle_sip_object_weak_unref(void *obj, belle_sip_object_destroy_notify_t destroy_notify, void *userpointer){ belle_sip_object_t *o=BELLE_SIP_OBJECT(obj); weak_ref_t *ref,*prevref=NULL,*next=NULL; if (o->ref==-1) return; /*too late and avoid recursions*/ for(ref=o->weak_refs;ref!=NULL;ref=next){ next=ref->next; if (ref->notify==destroy_notify && ref->userpointer==userpointer){ if (prevref==NULL) o->weak_refs=next; else prevref->next=next; belle_sip_free(ref); return; }else{ prevref=ref; } } belle_sip_fatal("Could not find weak_ref, you're a looser."); }
static void testIPV6URI_base(const char* ip6) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri; char* l_raw_uri; char uri[256]; snprintf(uri,sizeof(uri),"sip:toto@[%s]:5060;transport=tcp",ip6); L_uri = belle_sip_uri_parse(uri); l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "toto"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri),ip6); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(L_uri), "tcp"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void _linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy, LpConfig *config, int index) { char *section; bctbx_list_t *l = NULL; section = belle_sip_strdup_printf("nat_policy_%i", index); lp_config_set_string(config, section, "ref", policy->ref); lp_config_set_string(config, section, "stun_server", policy->stun_server); lp_config_set_string(config, section, "stun_server_username", policy->stun_server_username); if (linphone_nat_policy_upnp_enabled(policy)) { l = bctbx_list_append(l, "upnp"); } else { if (linphone_nat_policy_stun_enabled(policy)) l = bctbx_list_append(l, "stun"); if (linphone_nat_policy_turn_enabled(policy)) l = bctbx_list_append(l, "turn"); if (linphone_nat_policy_ice_enabled(policy)) l = bctbx_list_append(l, "ice"); } lp_config_set_string_list(config, section, "protocols", l); belle_sip_free(section); bctbx_list_free(l); }
static void test_session_description(void) { const char* l_src = big_sdp; belle_sdp_origin_t* l_origin; belle_sdp_session_description_t* lTmp; belle_sip_list_t* media_descriptions; belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(l_src); char* l_raw_session_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_session_description)); belle_sip_object_unref(BELLE_SIP_OBJECT(l_session_description)); lTmp = belle_sdp_session_description_parse(l_raw_session_description); belle_sip_free(l_raw_session_description); l_session_description = BELLE_SDP_SESSION_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_version(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_version_get_version(belle_sdp_session_description_get_version(l_session_description)),0); l_origin = belle_sdp_session_description_get_origin(l_session_description); CU_ASSERT_PTR_NOT_NULL(l_origin); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(l_origin),"2a01:e35:1387:1020:6233:4bff:fe0b:5663") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(l_origin),"IP6") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(l_origin),"IN") CU_ASSERT_EQUAL(belle_sdp_origin_get_session_id(l_origin),1239) CU_ASSERT_EQUAL(belle_sdp_origin_get_session_version(l_origin),1239) CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_session_name(l_session_description)); CU_ASSERT_STRING_EQUAL(belle_sdp_session_name_get_value(belle_sdp_session_description_get_session_name(l_session_description)),"SIP Talk"); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_connection(l_session_description)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_time_descriptions(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_time_get_start(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); CU_ASSERT_EQUAL(belle_sdp_time_get_stop(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); media_descriptions = belle_sdp_session_description_get_media_descriptions(l_session_description); CU_ASSERT_PTR_NOT_NULL(media_descriptions); CU_ASSERT_STRING_EQUAL (belle_sdp_media_get_media_type(belle_sdp_media_description_get_media((belle_sdp_media_description_t*)(media_descriptions->data))),"audio"); media_descriptions=media_descriptions->next; CU_ASSERT_PTR_NOT_NULL(media_descriptions); test_media_description_base((belle_sdp_media_description_t*)(media_descriptions->data)); belle_sip_object_unref(l_session_description); return; }
void belle_sip_object_weak_unref(void *obj, belle_sip_object_destroy_notify_t destroy_notify, void *userpointer){ belle_sip_object_t *o=BELLE_SIP_OBJECT(obj); weak_ref_t *ref,*prevref=NULL,*next=NULL; int found=FALSE; if (o->ref==-1) return; /*too late and avoid recursions*/ for(ref=o->weak_refs;ref!=NULL;ref=next){ next=ref->next; if (ref->notify==destroy_notify && ref->userpointer==userpointer){ if (prevref==NULL) o->weak_refs=next; else prevref->next=next; belle_sip_free(ref); found=TRUE; /*do not break or return, someone could have put twice the same weak ref on the same object*/ }else{ prevref=ref; } } if (!found) belle_sip_fatal("Could not find weak_ref, you're a looser."); }
char *belle_sip_object_describe_type_from_name(const char *name){ char *vptr_name; void *handle; void *symbol; handle=dlopen(NULL,RTLD_LAZY); if (handle==NULL){ belle_sip_error("belle_sip_object_describe_type_from_name: dlopen() failed: %s",dlerror()); return NULL; } vptr_name=belle_sip_strdup_printf("%s_vptr",name); symbol=dlsym(handle,vptr_name); belle_sip_free(vptr_name); dlclose(handle); if (symbol==NULL){ belle_sip_error("belle_sip_object_describe_type_from_name: could not find vptr for type %s",name); return NULL; } return _belle_sip_object_describe_type((belle_sip_object_vptr_t*)symbol); }
void linphone_nat_policy_save_to_config(const LinphoneNatPolicy *policy) { LpConfig *config = policy->lc->config; char *section; int index; bool_t finished = FALSE; for (index = 0; finished != TRUE; index++) { section = belle_sip_strdup_printf("nat_policy_%i", index); if (lp_config_has_section(config, section)) { const char *config_ref = lp_config_get_string(config, section, "ref", NULL); if ((config_ref != NULL) && (strcmp(config_ref, policy->ref) == 0)) { _linphone_nat_policy_save_to_config(policy, config, index); finished = TRUE; } } else { _linphone_nat_policy_save_to_config(policy, config, index); finished = TRUE; } belle_sip_free(section); } }
static void test_complex_uri(void) { belle_generic_uri_t* source_uri = belle_generic_uri_parse("ftp://*****:*****@ftp.linphone.fr:1234/url?sa=t&rct=j&url=http%3A%2F%2Ftranslate.google.fr"); char* source_uri_raw = belle_generic_uri_to_string(source_uri); belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw); belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri))); belle_sip_free(source_uri_raw); belle_sip_object_unref(source_uri); belle_sip_object_unref(first_uri); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"ftp"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user(uri),"toto"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user_password(uri),"secret"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/url"); BC_ASSERT_EQUAL(belle_generic_uri_get_port(uri),1234,int,"%d"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_query(uri),"sa=t&rct=j&url=http://translate.google.fr"); belle_sip_object_unref(uri); }