Commit 12f74f83 authored by Simon Morlat's avatar Simon Morlat

http implementation in progress

parent 0468d8a7
......@@ -486,6 +486,7 @@ struct addrinfo * belle_sip_ip_address_to_addrinfo(int family, const char *ipadd
}
err=getaddrinfo(ipaddress,serv,&hints,&res);
if (err!=0){
belle_sip_error("belle_sip_ip_address_to_addrinfo(): getaddrinfo() error: %s",gai_strerror(err));
return NULL;
}
return res;
......
......@@ -414,17 +414,29 @@ static void update_inactivity_timer(belle_sip_channel_t *obj, int from_recv){
obj->last_recv_time=belle_sip_time_ms();
}
/*constructor for channels creating an outgoing connection
* bindip local ip address to bind on, typically 0.0.0.0 or ::0
* locaport locaport to use for binding, can be set to 0 if port doesn't matter
* peer_cname canonical name of remote host, used for TLS verification
* peername peer's hostname, either ip address or DNS name
* pee_port peer's port to connect to.
*/
void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack,const char *bindip,int localport,const char *peer_cname, const char *peername, int peer_port){
/*to initialize our base class:*/
belle_sip_channel_set_socket(obj,-1,NULL);
/*then initialize members*/
obj->ai_family=AF_INET;
obj->peer_cname=peer_cname ? belle_sip_strdup(peer_cname) : NULL;
obj->peer_name=belle_sip_strdup(peername);
obj->peer_port=peer_port;
obj->stack=stack;
if (bindip && strcmp(bindip,"::0")!=0 && strcmp(bindip,"0.0.0.0")!=0)
obj->local_ip=belle_sip_strdup(bindip);
if (bindip){
if (strcmp(bindip,"::0")!=0 && strcmp(bindip,"0.0.0.0")!=0)
obj->local_ip=belle_sip_strdup(bindip);
if (strchr(bindip,':')!=NULL)
obj->ai_family=AF_INET6;
}
obj->local_port=localport;
obj->simulated_recv_return=1;/*not set*/
if (peername){
......@@ -437,6 +449,7 @@ void belle_sip_channel_init(belle_sip_channel_t *obj, belle_sip_stack_t *stack,c
update_inactivity_timer(obj,FALSE);
}
/*constructor for channels created by incoming connections*/
void belle_sip_channel_init_with_addr(belle_sip_channel_t *obj, belle_sip_stack_t *stack, const struct sockaddr *peer_addr, socklen_t addrlen){
char remoteip[64];
struct addrinfo ai;
......@@ -449,6 +462,7 @@ void belle_sip_channel_init_with_addr(belle_sip_channel_t *obj, belle_sip_stack_
belle_sip_addrinfo_to_ip(&ai,remoteip,sizeof(remoteip),&peer_port);
belle_sip_channel_init(obj,stack,NULL,0,NULL,remoteip,peer_port);
obj->peer_list=obj->current_peer=belle_sip_ip_address_to_addrinfo(ai.ai_family, obj->peer_name,obj->peer_port);
obj->ai_family=ai.ai_family;
}
void belle_sip_channel_set_socket(belle_sip_channel_t *obj, belle_sip_socket_t sock, belle_sip_source_func_t datafunc){
......@@ -754,10 +768,10 @@ 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);
if (belle_sip_stack_dns_srv_enabled(obj->stack))
obj->resolver_ctx=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 (belle_sip_stack_dns_srv_enabled(obj->stack) && obj->lp!=NULL)
obj->resolver_ctx=belle_sip_stack_resolve(obj->stack, belle_sip_channel_get_transport_name_lower_case(obj), obj->peer_name, obj->peer_port, obj->ai_family, channel_res_done, obj);
else
obj->resolver_ctx=belle_sip_stack_resolve_a(obj->stack, obj->peer_name, obj->peer_port, obj->lp->ai_family, channel_res_done, obj);
obj->resolver_ctx=belle_sip_stack_resolve_a(obj->stack, obj->peer_name, obj->peer_port, obj->ai_family, channel_res_done, obj);
if (obj->resolver_ctx){
belle_sip_object_ref(obj->resolver_ctx);
}
......
......@@ -80,6 +80,7 @@ struct belle_sip_channel{
belle_sip_listening_point_t *lp; /*the listening point that owns this channel*/
belle_sip_channel_state_t state;
belle_sip_list_t *listeners;
int ai_family;
char *peer_cname;
char *peer_name;
int peer_port;
......
......@@ -140,6 +140,7 @@ BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_http_channel_context_t,belle_si
BELLE_SIP_INSTANCIATE_VPTR(belle_http_channel_context_t,belle_sip_object_t,belle_http_channel_context_uninit,NULL,NULL,FALSE);
static void http_provider_uninit(belle_http_provider_t *obj){
belle_sip_message("http provider destroyed.");
belle_sip_list_for_each(obj->tcp_channels,(void (*)(void*))belle_sip_channel_force_close);
belle_sip_list_free_with_data(obj->tcp_channels,belle_sip_object_unref);
belle_sip_list_for_each(obj->tls_channels,(void (*)(void*))belle_sip_channel_force_close);
......@@ -162,6 +163,7 @@ static void split_request_url(belle_http_request_t *req){
belle_generic_uri_t *new_uri=belle_generic_uri_new();
char *host_value;
belle_sip_message("Path is: %s",belle_generic_uri_get_path(uri));
belle_generic_uri_set_path(new_uri,belle_generic_uri_get_path(uri));
if (belle_generic_uri_get_port(uri)>0)
host_value=belle_sip_strdup_printf("%s:%i",belle_generic_uri_get_host(uri),belle_generic_uri_get_port(uri));
......
......@@ -50,14 +50,22 @@ belle_sip_hop_t* belle_sip_hop_new_from_generic_uri(const belle_generic_uri_t *u
const char *host;
const char * transport="TCP";
const char *scheme=belle_generic_uri_get_scheme(uri);
int port=belle_generic_uri_get_port(uri);
int well_known_port=0;
host=belle_generic_uri_get_host(uri);
if (strcasecmp(scheme,"https")==0) transport="TLS";
if (strcasecmp(scheme,"http")==0) {
transport="TCP";
well_known_port=80;
}else if (strcasecmp(scheme,"https")==0) {
transport="TLS";
well_known_port=443;
}
return belle_sip_hop_new(transport,
host,
host,
belle_generic_uri_get_port(uri));
port > 0 ? port : well_known_port);
}
static void belle_sip_hop_destroy(belle_sip_hop_t *hop){
......
......@@ -234,6 +234,7 @@ belle_sip_channel_t * belle_sip_stream_channel_new_client(belle_sip_stack_t *sta
return (belle_sip_channel_t*)obj;
}
/*child of server socket*/
belle_sip_channel_t * belle_sip_stream_channel_new_child(belle_sip_stack_t *stack, belle_sip_socket_t sock, struct sockaddr *remote_addr, socklen_t slen){
struct sockaddr_storage localaddr;
socklen_t local_len=sizeof(localaddr);
......
......@@ -56,7 +56,7 @@ static void one_get(void){
NULL);
cbs.process_response=process_response;
cbs.process_io_error=process_io_error;
l=belle_http_request_listener_create_from_callbacks(&cbs,NULL);
l=belle_http_request_listener_create_from_callbacks(&cbs,&counters);
belle_http_provider_send_request(prov,req,l);
belle_sip_stack_sleep(stack,5000);
CU_ASSERT_TRUE(counters.response_count==1);
......
......@@ -175,7 +175,7 @@ int belle_sip_tester_run_tests(const char *suite_name, const char *test_name) {
if (test_name) {
CU_pTest test=CU_get_test_by_name(test_name, suite);
if (test==NULL){
fprintf(stderr,"There is no suite named '%s'",suite_name);
fprintf(stderr,"There is no test named '%s'",suite_name);
exit(-1);
}
CU_basic_run_test(suite, test);
......
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