Commit bfb0bf99 authored by Simon Morlat's avatar Simon Morlat

belle-sip fully works on windows (mingw).

parent 3d52f64a
......@@ -181,24 +181,34 @@ void belle_sip_resolve_cancel(belle_sip_main_loop_t *ml, unsigned long id){
}
void belle_sip_get_src_addr_for(const struct sockaddr *dest, socklen_t destlen, struct sockaddr *src, socklen_t *srclen){
int af_type=(destlen==sizeof(struct sockaddr_in6)) ? AF_INET6 : AF_INET;
int af_type=dest->sa_family;
int sock=socket(af_type,SOCK_DGRAM,IPPROTO_UDP);
memset(src,0,*srclen);
if (sock==(belle_sip_socket_t)-1){
belle_sip_fatal("Could not create socket: %s",get_socket_error());
return;
belle_sip_fatal("Could not create socket: %s",belle_sip_get_socket_error_string());
goto fail;
}
if (connect(sock,dest,destlen)==-1){
belle_sip_error("belle_sip_get_src_addr_for: connect() failed: %s",get_socket_error());
close(sock);
return;
belle_sip_error("belle_sip_get_src_addr_for: connect() failed: %s",belle_sip_get_socket_error_string());
goto fail;
}
if (getsockname(sock,src,srclen)==-1){
belle_sip_error("belle_sip_get_src_addr_for: getsockname() failed: %s",get_socket_error());
close(sock);
return;
belle_sip_error("belle_sip_get_src_addr_for: getsockname() failed: %s",belle_sip_get_socket_error_string());
goto fail;
}
close_socket(sock);
return;
fail:
{
struct addrinfo hints={0},*res=NULL;
int err;
hints.ai_family=af_type;
err=getaddrinfo(af_type==AF_INET ? "0.0.0.0" : "::0","0",&hints,&res);
if (err!=0) belle_sip_fatal("belle_sip_get_src_addr_for(): getaddrinfo failed: %s",belle_sip_get_socket_error_string_from_code(err));
memcpy(src,res->ai_addr,MIN(*srclen,res->ai_addrlen));
*srclen=res->ai_addrlen;
freeaddrinfo(res);
}
if (sock==(belle_sip_socket_t)-1) close_socket(sock);
}
......@@ -71,10 +71,13 @@ static int tls_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
#ifdef HAVE_GNUTLS
static ssize_t tls_channel_pull_func(gnutls_transport_ptr_t obj, void* buff, size_t bufflen) {
belle_sip_tls_channel_t* channel = (belle_sip_tls_channel_t*)obj;
int err=recv(
belle_sip_source_get_socket((belle_sip_source_t *)obj),buff,bufflen,0);
if (err==-1 && get_socket_error()!=EWOULDBLOCK){
belle_sip_error("tls_channel_pull_func: %s",belle_sip_get_socket_error_string());
if (err==-1){
if (get_socket_error()!=EWOULDBLOCK){
belle_sip_error("tls_channel_pull_func: %s",belle_sip_get_socket_error_string());
}else gnutls_transport_set_errno(channel->session,EAGAIN); /*necessary on windows*/
}
return err;
}
......@@ -147,7 +150,7 @@ static int tls_process_data(belle_sip_channel_t *obj,unsigned int revents){
}
/*connected, now establishing TLS connection*/
#if HAVE_GNUTLS
gnutls_transport_set_ptr2(channel->session, (gnutls_transport_ptr_t)channel,(gnutls_transport_ptr_t) (0xFFFFFFFFUL&fd));
gnutls_transport_set_ptr2(channel->session, (gnutls_transport_ptr_t)channel,(gnutls_transport_ptr_t) (long)fd);
result = gnutls_handshake(channel->session);
if ((result < 0 && gnutls_error_is_fatal (result) == 0)) {
belle_sip_message("TLS connection in progress for channel [%p]",channel);
......
......@@ -65,7 +65,7 @@ int udp_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
socklen_t lslen=sizeof(laddr);
if (obj->local_ip==NULL){
belle_sip_get_src_addr_for(ai->ai_addr,ai->ai_addrlen,(struct sockaddr*)&laddr,&lslen);
if (lslen==sizeof(struct sockaddr_in6)){
if (ai->ai_family==AF_INET6){
struct sockaddr_in6 *sin6=(struct sockaddr_in6*)&laddr;
sin6->sin6_port=htons(obj->local_port);
}else{
......@@ -105,7 +105,7 @@ belle_sip_channel_t * belle_sip_channel_new_udp(belle_sip_stack_t *stack, int so
belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *stack, int sock, const char *bindip, int localport, const struct addrinfo *peer){
belle_sip_udp_channel_t *obj=belle_sip_object_new(belle_sip_udp_channel_t);
struct addrinfo ai;
struct addrinfo ai,hints={0};
char name[NI_MAXHOST];
char serv[NI_MAXSERV];
int err;
......@@ -119,9 +119,10 @@ belle_sip_channel_t * belle_sip_channel_new_udp_with_addr(belle_sip_stack_t *sta
return NULL;
}
belle_sip_channel_init((belle_sip_channel_t*)obj,stack,bindip,localport,name,atoi(serv));
err=getaddrinfo(name,serv,&ai,&obj->base.peer); /*might be optimized someway ?*/
hints.ai_family=peer->ai_family;
err=getaddrinfo(name,serv,&hints,&obj->base.peer); /*might be optimized someway ?*/
if (err!=0){
belle_sip_error("getaddrinfo() failed for channel [%p] error [%s]",obj,gai_strerror(err));
belle_sip_error("getaddrinfo() failed for udp channel [%p] error [%s]",obj,gai_strerror(err));
}
return (belle_sip_channel_t*)obj;
}
......
......@@ -107,10 +107,12 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
}else{
belle_sip_channel_t *chan;
struct addrinfo ai={0};
ai.ai_family=((struct sockaddr*)&addr)->sa_family;
ai.ai_addr=(struct sockaddr*)&addr;
ai.ai_addrlen=addrlen;
chan=_belle_sip_listening_point_get_channel((belle_sip_listening_point_t*)lp,NULL,0,&ai);
if (chan==NULL){
/*TODO: should rather create the channel with real local ip and port and not just 0.0.0.0"*/
chan=belle_sip_channel_new_udp_with_addr(lp->base.stack
,lp->sock
,belle_sip_uri_get_host(lp->base.listening_uri)
......
......@@ -256,6 +256,9 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
const char* identity = "sip:" USERNAME "@" SIPDOMAIN ;
const char* domain="sip:" SIPDOMAIN ;
belle_sip_header_contact_t* contact=belle_sip_header_contact_new();
belle_sip_uri_t *dest_uri;
endpoint_t* client,*server;
memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
......@@ -265,11 +268,14 @@ static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t
client_callbacks.process_auth_requested=client_process_auth_requested;
server_callbacks.process_request_event=server_process_request_event;
endpoint_t* client = create_udp_endpoint(3452,&client_callbacks);
endpoint_t* server = create_udp_endpoint(6788,&server_callbacks);
client = create_udp_endpoint(3452,&client_callbacks);
server = create_udp_endpoint(6788,&server_callbacks);
server->expire_in_contact=expire_in_contact;
server->auth=auth_mode;
destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,(belle_sip_uri_t*)belle_sip_listening_point_get_uri(server->lp)));
dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp));
belle_sip_uri_set_host(dest_uri,"127.0.0.1");
destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,dest_uri));
req=belle_sip_request_create(
......@@ -327,6 +333,8 @@ static void subscribe_test() {
belle_sip_header_route_t* destination_route;
const char* identity = "sip:" USERNAME "@" SIPDOMAIN ;
const char* domain="sip:" SIPDOMAIN ;
endpoint_t* client,*server;
belle_sip_uri_t *dest_uri;
belle_sip_header_contact_t* contact=belle_sip_header_contact_new();
memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t));
......@@ -335,11 +343,14 @@ static void subscribe_test() {
client_callbacks.process_auth_requested=client_process_auth_requested;
server_callbacks.process_request_event=server_process_request_event;
endpoint_t* client = create_udp_endpoint(3452,&client_callbacks);
endpoint_t* server = create_udp_endpoint(6788,&server_callbacks);
client = create_udp_endpoint(3452,&client_callbacks);
server = create_udp_endpoint(6788,&server_callbacks);
server->expire_in_contact=0;
server->auth=digest_auth;
destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,(belle_sip_uri_t*)belle_sip_listening_point_get_uri(server->lp)));
dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp));
belle_sip_uri_set_host(dest_uri,"127.0.0.1");
destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,dest_uri));
req=belle_sip_request_create(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment