Commit 79301d72 authored by Simon Morlat's avatar Simon Morlat

enable SRV resolution (was still A or AAAA)

fix test "bad request" that was not working at all.
parent c181d4a1
...@@ -43,7 +43,7 @@ BELLE_SIP_BEGIN_DECLS ...@@ -43,7 +43,7 @@ BELLE_SIP_BEGIN_DECLS
int belle_sip_addrinfo_to_ip(const struct addrinfo *ai, char *ip, size_t ip_size, int *port); int belle_sip_addrinfo_to_ip(const struct addrinfo *ai, char *ip, size_t ip_size, int *port);
BELLESIP_EXPORT struct addrinfo * belle_sip_ip_address_to_addrinfo(int family, const char *ipaddress, int port); BELLESIP_EXPORT struct addrinfo * belle_sip_ip_address_to_addrinfo(int family, const char *ipaddress, int port);
BELLESIP_EXPORT unsigned long belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *name, const char *transport, int port, int family, belle_sip_resolver_callback_t cb, void *data); BELLESIP_EXPORT unsigned long belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *transport, const char *name, int port, int family, belle_sip_resolver_callback_t cb, void *data);
BELLESIP_EXPORT unsigned long belle_sip_stack_resolve_a(belle_sip_stack_t *stack, const char *name, int port, int family, belle_sip_resolver_callback_t cb, void *data); BELLESIP_EXPORT unsigned long belle_sip_stack_resolve_a(belle_sip_stack_t *stack, const char *name, int port, int family, belle_sip_resolver_callback_t cb, void *data);
BELLESIP_EXPORT unsigned long belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *name, const char *transport, belle_sip_resolver_srv_callback_t cb, void *data); BELLESIP_EXPORT unsigned long belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *name, const char *transport, belle_sip_resolver_srv_callback_t cb, void *data);
BELLESIP_EXPORT void belle_sip_stack_resolve_cancel(belle_sip_stack_t *stack, unsigned long id); BELLESIP_EXPORT void belle_sip_stack_resolve_cancel(belle_sip_stack_t *stack, unsigned long id);
......
...@@ -148,6 +148,7 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int ...@@ -148,6 +148,7 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int
struct dns_rr_i *I; struct dns_rr_i *I;
struct dns_rr_i dns_rr_it; struct dns_rr_i dns_rr_it;
int error; int error;
int gai_err;
if (revents & BELLE_SIP_EVENT_TIMEOUT) { if (revents & BELLE_SIP_EVENT_TIMEOUT) {
belle_sip_error("%s timed-out", __FUNCTION__); belle_sip_error("%s timed-out", __FUNCTION__);
...@@ -187,8 +188,10 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int ...@@ -187,8 +188,10 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int
memcpy(&sin6.sin6_addr, &aaaa->addr, sizeof(sin6.sin6_addr)); memcpy(&sin6.sin6_addr, &aaaa->addr, sizeof(sin6.sin6_addr));
sin6.sin6_family = AF_INET6; sin6.sin6_family = AF_INET6;
sin6.sin6_port = ctx->port; sin6.sin6_port = ctx->port;
if (getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), host, sizeof(host), NULL, 0, NI_NUMERICHOST) != 0) if ((gai_err=getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), host, sizeof(host), NULL, 0, NI_NUMERICHOST)) != 0){
belle_sip_error("resolver_process_data(): getnameinfo() failed for ipv6: %s",gai_strerror(gai_err));
continue; continue;
}
ctx->ai_list = ai_list_append(ctx->ai_list, belle_sip_ip_address_to_addrinfo(ctx->family, host, ctx->port)); ctx->ai_list = ai_list_append(ctx->ai_list, belle_sip_ip_address_to_addrinfo(ctx->family, host, ctx->port));
belle_sip_message("%s resolved to %s", ctx->name, host); belle_sip_message("%s resolved to %s", ctx->name, host);
} else if ((ctx->type == DNS_T_A) && (rr.class == DNS_C_IN) && (rr.type == DNS_T_A)) { } else if ((ctx->type == DNS_T_A) && (rr.class == DNS_C_IN) && (rr.type == DNS_T_A)) {
...@@ -198,8 +201,10 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int ...@@ -198,8 +201,10 @@ static int resolver_process_data(belle_sip_resolver_context_t *ctx, unsigned int
memcpy(&sin.sin_addr, &a->addr, sizeof(sin.sin_addr)); memcpy(&sin.sin_addr, &a->addr, sizeof(sin.sin_addr));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_port = ctx->port; sin.sin_port = ctx->port;
if (getnameinfo((struct sockaddr *)&sin, sizeof(sin), host, sizeof(host), NULL, 0, NI_NUMERICHOST) != 0) if ((gai_err=getnameinfo((struct sockaddr *)&sin, sizeof(sin), host, sizeof(host), NULL, 0, NI_NUMERICHOST)) != 0){
belle_sip_error("resolver_process_data(): getnameinfo() failed: %s",gai_strerror(gai_err));
continue; continue;
}
ctx->ai_list = ai_list_append(ctx->ai_list, belle_sip_ip_address_to_addrinfo(ctx->family, host, ctx->port)); ctx->ai_list = ai_list_append(ctx->ai_list, belle_sip_ip_address_to_addrinfo(ctx->family, host, ctx->port));
belle_sip_message("%s resolved to %s", ctx->name, host); belle_sip_message("%s resolved to %s", ctx->name, host);
} else if ((ctx->type == DNS_T_SRV) && (rr.class == DNS_C_IN) && (rr.type == DNS_T_SRV)) { } else if ((ctx->type == DNS_T_SRV) && (rr.class == DNS_C_IN) && (rr.type == DNS_T_SRV)) {
......
...@@ -736,7 +736,7 @@ static void channel_res_done(void *data, const char *name, struct addrinfo *ai_l ...@@ -736,7 +736,7 @@ static void channel_res_done(void *data, const char *name, struct addrinfo *ai_l
void belle_sip_channel_resolve(belle_sip_channel_t *obj){ void belle_sip_channel_resolve(belle_sip_channel_t *obj){
channel_set_state(obj,BELLE_SIP_CHANNEL_RES_IN_PROGRESS); channel_set_state(obj,BELLE_SIP_CHANNEL_RES_IN_PROGRESS);
obj->resolver_id=belle_sip_stack_resolve_a(obj->stack, obj->peer_name, obj->peer_port, obj->lp->ai_family, channel_res_done, obj); obj->resolver_id=belle_sip_stack_resolve(obj->stack, belle_sip_channel_get_transport_name_lower_case(obj), obj->peer_name, obj->peer_port, obj->lp->ai_family, channel_res_done, obj);
if (obj->resolver_id==-1){ if (obj->resolver_id==-1){
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR); channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
} }
......
...@@ -382,9 +382,11 @@ static void bad_req_process_io_error(void *user_ctx, const belle_sip_io_error_ev ...@@ -382,9 +382,11 @@ static void bad_req_process_io_error(void *user_ctx, const belle_sip_io_error_ev
} }
static void bad_req_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){ static void bad_req_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
BELLESIP_UNUSED(user_ctx); int *bad_request_response_received=(int*)user_ctx;
BELLESIP_UNUSED(event); belle_sip_response_t *resp=belle_sip_response_event_get_response(event);
belle_sip_message("bad_req_process_response_event not implemented yet"); CU_ASSERT_TRUE(resp && belle_sip_response_get_status_code(resp)==400);
*bad_request_response_received=1;
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
} }
static void test_bad_request(void) { static void test_bad_request(void) {
...@@ -395,11 +397,13 @@ static void test_bad_request(void) { ...@@ -395,11 +397,13 @@ static void test_bad_request(void) {
belle_sip_header_route_t* route; belle_sip_header_route_t* route;
belle_sip_header_to_t* to = belle_sip_header_to_create2("sip:toto@titi.com",NULL); belle_sip_header_to_t* to = belle_sip_header_to_create2("sip:toto@titi.com",NULL);
belle_sip_listener_callbacks_t cbs; belle_sip_listener_callbacks_t cbs;
int bad_request_response_received=0;
memset(&cbs,0,sizeof(cbs)); memset(&cbs,0,sizeof(cbs));
bad_req_listener = belle_sip_listener_create_from_callbacks(&cbs,NULL);
cbs.process_io_error=bad_req_process_io_error; cbs.process_io_error=bad_req_process_io_error;
cbs.process_response_event=bad_req_process_response_event; cbs.process_response_event=bad_req_process_response_event;
bad_req_listener = belle_sip_listener_create_from_callbacks(&cbs,&bad_request_response_received);
req=belle_sip_request_create( req=belle_sip_request_create(
BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(route_address)))), BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(route_address)))),
...@@ -421,7 +425,8 @@ static void test_bad_request(void) { ...@@ -421,7 +425,8 @@ static void test_bad_request(void) {
belle_sip_provider_add_sip_listener(prov,bad_req_listener); belle_sip_provider_add_sip_listener(prov,bad_req_listener);
t=belle_sip_provider_create_client_transaction(prov,req); t=belle_sip_provider_create_client_transaction(prov,req);
belle_sip_client_transaction_send_request(t); belle_sip_client_transaction_send_request(t);
belle_sip_stack_sleep(stack,100); belle_sip_stack_sleep(stack,3000);
CU_ASSERT_TRUE(bad_request_response_received==1);
belle_sip_provider_remove_sip_listener(prov,bad_req_listener); belle_sip_provider_remove_sip_listener(prov,bad_req_listener);
belle_sip_object_unref(bad_req_listener); belle_sip_object_unref(bad_req_listener);
} }
......
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