Commit 957298c1 authored by Simon Morlat's avatar Simon Morlat

http in progress

parent 934dd1d9
......@@ -175,6 +175,7 @@ typedef struct belle_http_url belle_http_url_t;
#include "belle-sip/auth-helper.h"
#include "belle-sip/http-listener.h"
#include "belle-sip/http-provider.h"
#include "belle-sip/http-message.h"
#undef TRUE
......
......@@ -24,6 +24,7 @@
BELLE_SIP_BEGIN_DECLS
belle_http_url_t *belle_http_request_get_url(belle_http_request_t *req);
BELLE_SIP_END_DECLS
......
......@@ -25,7 +25,7 @@ BELLE_SIP_BEGIN_DECLS
#define BELLE_SIP_HTTP_PROVIDER(obj) BELLE_SIP_CAST(obj,belle_http_provider_t)
BELLESIP_EXPORT void belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener);
BELLESIP_EXPORT int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener);
BELLE_SIP_END_DECLS
......
......@@ -40,7 +40,7 @@ BELLESIP_EXPORT void belle_sip_stack_delete_listening_point(belle_sip_stack_t *s
BELLESIP_EXPORT belle_sip_provider_t *belle_sip_stack_create_provider(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
BELLESIP_EXPORT belle_http_provider_t * belle_sip_stack_create_http_provider(belle_sip_stack_t *s);
BELLESIP_EXPORT belle_http_provider_t * belle_sip_stack_create_http_provider(belle_sip_stack_t *s, const char *bind_ip);
BELLESIP_EXPORT belle_sip_main_loop_t* belle_sip_stack_get_main_loop(belle_sip_stack_t *stack);
......
......@@ -560,7 +560,7 @@ typedef struct listener_ctx{
/*
* http provider
*/
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s);
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s, const char *bind_ip);
/*
......
......@@ -783,4 +783,32 @@ void belle_sip_channel_force_close(belle_sip_channel_t *obj){
channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED);
}
belle_sip_channel_t *belle_sip_channel_find_from_list_with_addrinfo(belle_sip_list_t *l, const belle_sip_hop_t *hop, const struct addrinfo *addr){
belle_sip_list_t *elem;
belle_sip_channel_t *chan;
for(elem=l;elem!=NULL;elem=elem->next){
chan=(belle_sip_channel_t*)elem->data;
if (belle_sip_channel_matches(chan,hop,addr)){
return chan;
}
}
return NULL;
}
belle_sip_channel_t *belle_sip_channel_find_from_list(belle_sip_list_t *l ,const belle_sip_hop_t *hop){
struct addrinfo *res=NULL;
struct addrinfo hints={0};
char portstr[20];
belle_sip_channel_t *chan;
hints.ai_flags=AI_NUMERICHOST|AI_NUMERICSERV;
snprintf(portstr,sizeof(portstr),"%i",hop->port);
getaddrinfo(hop->host,portstr,&hints,&res);
chan=belle_sip_channel_find_from_list_with_addrinfo(l,hop,res);
if (res) freeaddrinfo(res);
return chan;
}
......@@ -182,6 +182,9 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
void belle_sip_tls_channel_set_client_certificates_chain(belle_sip_tls_channel_t *obj, belle_sip_certificates_chain_t* cert_chain);
void belle_sip_tls_channel_set_client_certificate_key(belle_sip_tls_channel_t *obj, belle_sip_signing_key_t* key);
belle_sip_channel_t *belle_sip_channel_find_from_list_with_addrinfo(belle_sip_list_t *l, const belle_sip_hop_t *hop, const struct addrinfo *addr);
belle_sip_channel_t *belle_sip_channel_find_from_list(belle_sip_list_t *l ,const belle_sip_hop_t *hop);
#define BELLE_SIP_TLS_CHANNEL(obj) BELLE_SIP_CAST(obj,belle_sip_tls_channel_t)
#endif
......@@ -61,3 +61,7 @@ void belle_http_request_set_listener(belle_http_request_t *req, belle_http_reque
if (l)
belle_sip_object_weak_ref(l,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
}
belle_http_url_t *belle_http_request_get_url(belle_http_request_t *req){
return req->req_url;
}
......@@ -30,6 +30,7 @@ struct belle_http_channel_context{
struct belle_http_provider{
belle_sip_stack_t *stack;
char *bind_ip;
belle_sip_list_t *tcp_channels;
belle_sip_list_t *tls_channels;
};
......@@ -103,15 +104,36 @@ static void http_provider_uninit(belle_http_provider_t *obj){
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_http_provider_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_http_provider_t,belle_sip_object_t,http_provider_uninit,NULL,NULL,FALSE);
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s){
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s, const char *bind_ip){
belle_http_provider_t *p=belle_sip_object_new(belle_http_provider_t);
p->stack=s;
p->bind_ip=belle_sip_strdup(bind_ip);
return p;
}
void belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){
/*belle_sip_channel_t *chan;*/
int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){
belle_sip_channel_t *chan;
belle_sip_hop_t *hop=NULL;//belle_sip_hop_new_from_uri(belle_http_request_get_url(req));
belle_sip_list_t **channels=NULL;
if (strcasecmp(hop->transport,"tcp")==0) channels=&obj->tcp_channels;
else if (strcasecmp(hop->transport,"tls")==0) channels=&obj->tls_channels;
else{
belle_sip_error("belle_http_provider_send_request(): unsupported transport %s",hop->transport);
return -1;
}
belle_http_request_set_listener(req,listener);
chan=belle_sip_channel_find_from_list(*channels,hop);
if (!chan){
chan=belle_sip_stream_channel_new_client(obj->stack,obj->bind_ip,0,hop->cname,hop->host,hop->port);
belle_http_channel_context_new(chan);
*channels=belle_sip_list_prepend(*channels,chan);
}
belle_sip_object_unref(hop);
belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(req));
return 0;
}
......@@ -129,30 +129,11 @@ int belle_sip_listening_point_get_well_known_port(const char *transport){
}
belle_sip_channel_t *_belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp, const belle_sip_hop_t *hop, const struct addrinfo *addr){
belle_sip_list_t *elem;
belle_sip_channel_t *chan;
for(elem=lp->channels;elem!=NULL;elem=elem->next){
chan=(belle_sip_channel_t*)elem->data;
if (belle_sip_channel_matches(chan,hop,addr)){
return chan;
}
}
return NULL;
return belle_sip_channel_find_from_list_with_addrinfo(lp->channels,hop,addr);
}
belle_sip_channel_t *belle_sip_listening_point_get_channel(belle_sip_listening_point_t *lp,const belle_sip_hop_t *hop){
struct addrinfo *res=NULL;
struct addrinfo hints={0};
char portstr[20];
belle_sip_channel_t *chan;
hints.ai_flags=AI_NUMERICHOST|AI_NUMERICSERV;
snprintf(portstr,sizeof(portstr),"%i",hop->port);
getaddrinfo(hop->host,portstr,&hints,&res);
chan=_belle_sip_listening_point_get_channel(lp,hop,res);
if (res) freeaddrinfo(res);
return chan;
return belle_sip_channel_find_from_list(lp->channels,hop);
}
static int send_keep_alive(belle_sip_channel_t* obj) {
......
......@@ -134,8 +134,8 @@ belle_sip_provider_t *belle_sip_stack_create_provider(belle_sip_stack_t *s, bell
return p;
}
belle_http_provider_t *belle_sip_stack_create_http_provider(belle_sip_stack_t *s){
belle_http_provider_t *p=belle_http_provider_new(s);
belle_http_provider_t *belle_sip_stack_create_http_provider(belle_sip_stack_t *s, const char *bind_ip){
belle_http_provider_t *p=belle_http_provider_new(s, bind_ip);
return p;
}
......
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