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
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 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_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);
......
......@@ -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 dns_rr_it;
int error;
int gai_err;
if (revents & BELLE_SIP_EVENT_TIMEOUT) {
belle_sip_error("%s timed-out", __FUNCTION__);
......@@ -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));
sin6.sin6_family = AF_INET6;
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;
}
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);
} 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
memcpy(&sin.sin_addr, &a->addr, sizeof(sin.sin_addr));
sin.sin_family = AF_INET;
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;
}
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);
} 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
void belle_sip_channel_resolve(belle_sip_channel_t *obj){
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){
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
}
static void bad_req_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
BELLESIP_UNUSED(user_ctx);
BELLESIP_UNUSED(event);
belle_sip_message("bad_req_process_response_event not implemented yet");
int *bad_request_response_received=(int*)user_ctx;
belle_sip_response_t *resp=belle_sip_response_event_get_response(event);
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) {
......@@ -395,12 +397,14 @@ static void test_bad_request(void) {
belle_sip_header_route_t* route;
belle_sip_header_to_t* to = belle_sip_header_to_create2("sip:toto@titi.com",NULL);
belle_sip_listener_callbacks_t cbs;
int bad_request_response_received=0;
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_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(
BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(route_address)))),
"REGISTER",
......@@ -421,7 +425,8 @@ static void test_bad_request(void) {
belle_sip_provider_add_sip_listener(prov,bad_req_listener);
t=belle_sip_provider_create_client_transaction(prov,req);
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_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