Commit 934dd1d9 authored by Simon Morlat's avatar Simon Morlat

http in progress

parent 99dc5616
......@@ -20,6 +20,9 @@ bellesip_HEADERS=\
belle-sip.h \
refresher.h \
defs.h \
resolver.h
resolver.h \
http-provider.h \
http-message.h \
http-listener.h
EXTRA_DIST=$(bellesip_HEADERS)
......@@ -116,7 +116,8 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_combined_resolver_context_t),
BELLE_SIP_TYPE_ID(belle_http_provider_t),
BELLE_SIP_TYPE_ID(belle_http_request_t),
BELLE_SIP_TYPE_ID(belle_http_response_t)
BELLE_SIP_TYPE_ID(belle_http_response_t),
BELLE_SIP_TYPE_ID(belle_http_channel_context_t)
BELLE_SIP_DECLARE_TYPES_END
......@@ -151,9 +152,10 @@ typedef struct belle_sip_client_transaction belle_sip_client_transaction_t;
typedef struct _belle_sip_message belle_sip_message_t;
typedef struct _belle_sip_request belle_sip_request_t;
typedef struct _belle_sip_response belle_sip_response_t;
typedef struct _belle_http_request belle_http_request_t;
typedef struct _belle_http_response belle_http_response_t;
typedef struct belle_http_request belle_http_request_t;
typedef struct belle_http_response belle_http_response_t;
typedef struct belle_sip_hop belle_sip_hop_t;
typedef struct belle_http_url belle_http_url_t;
#include "belle-sip/utils.h"
#include "belle-sip/list.h"
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BELLE_HTTP_MESSAGE_H
#define BELLE_HTTP_MESSAGE_H
#define BELLE_HTTP_REQUEST(obj) BELLE_SIP_CAST(obj,belle_http_request_t)
#define BELLE_HTTP_RESPONSE(obj) BELLE_SIP_CAST(obj,belle_http_response_t)
BELLE_SIP_BEGIN_DECLS
BELLE_SIP_END_DECLS
#endif
......@@ -23,6 +23,8 @@
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);
BELLE_SIP_END_DECLS
......
......@@ -62,7 +62,9 @@ libbellesip_la_SOURCES= \
transports/stream_channel.h \
transports/stream_listeningpoint.c \
refresher.c \
dns.c dns.h
dns.c dns.h \
http-provider.c \
http-message.c
if BUILD_TUNNEL
libbellesip_la_SOURCES+= transports/tunnel_listeningpoint.c \
......
......@@ -191,6 +191,10 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_certificates_chain_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_signing_key_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dns_srv_t);
BELLE_SIP_DECLARE_VPTR(belle_http_provider_t);
BELLE_SIP_DECLARE_VPTR(belle_http_channel_context_t);
BELLE_SIP_DECLARE_VPTR(belle_http_request_t);
BELLE_SIP_DECLARE_VPTR(belle_http_response_t);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_resolver_context_t,belle_sip_source_t)
void (*cancel)(belle_sip_resolver_context_t *);
......@@ -558,6 +562,13 @@ typedef struct listener_ctx{
*/
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s);
/*
* SIP and http messages
**/
void belle_sip_message_init(belle_sip_message_t *message);
struct _belle_sip_message {
belle_sip_object_t base;
belle_sip_list_t* header_list;
......@@ -573,7 +584,9 @@ struct _belle_sip_request {
char *rfc2543_branch; /*computed 'branch' id in case we receive this request from an old RFC2543 stack*/
unsigned char dialog_queued;
};
void belle_http_request_set_listener(belle_http_request_t *req, belle_http_request_listener_t *l);
/*
belle_sip_transaction_t
*/
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
struct belle_http_request{
belle_sip_message_t base;
belle_http_url_t *req_url;
belle_http_request_listener_t *listener;
};
static void belle_http_request_listener_destroyed(belle_http_request_t *req){
req->listener=NULL;
}
static void belle_http_request_destroy(belle_http_request_t *req){
if (req->req_url) belle_sip_object_unref(req->req_url);
belle_http_request_set_listener(req,NULL);
}
static void belle_http_request_clone(belle_http_request_t *obj, const belle_http_request_t *orig){
if (orig->req_url) obj->req_url=(belle_http_url_t*)belle_sip_object_clone((belle_sip_object_t*)orig->req_url);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_http_request_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_http_request_t,belle_sip_message_t,belle_http_request_destroy,belle_http_request_clone,NULL,TRUE);
belle_http_request_t *belle_http_request_new(){
belle_http_request_t *obj=belle_sip_object_new(belle_http_request_t);
belle_sip_message_init((belle_sip_message_t*)obj);
return obj;
}
belle_http_request_t *belle_http_request_create(belle_http_url_t *url){
belle_http_request_t *obj=belle_http_request_new();
obj->req_url=(belle_http_url_t*)belle_sip_object_ref(url);
return obj;
}
void belle_http_request_set_listener(belle_http_request_t *req, belle_http_request_listener_t *l){
if (req->listener){
belle_sip_object_weak_unref(req->listener,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
req->listener=NULL;
}
if (l)
belle_sip_object_weak_ref(l,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
}
......@@ -19,6 +19,14 @@
#include "belle_sip_internal.h"
typedef struct belle_http_channel_context belle_http_channel_context_t;
#define BELLE_HTTP_CHANNEL_CONTEXT(obj) BELLE_SIP_CAST(obj,belle_http_channel_context_t)
struct belle_http_channel_context{
belle_sip_object_t base;
belle_sip_list_t *pending_requests;
};
struct belle_http_provider{
belle_sip_stack_t *stack;
......@@ -28,21 +36,19 @@ struct belle_http_provider{
static int channel_on_event(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, unsigned int revents){
if (revents & BELLE_SIP_EVENT_READ){
belle_sip_message_t *msg;
while ((msg=belle_sip_channel_pick_message(chan)))
belle_sip_provider_dispatch_message(BELLE_SIP_PROVIDER(obj),msg);
}
return 0;
}
static int channel_on_auth_requested(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, const char* distinguished_name){
if (BELLE_SIP_IS_INSTANCE_OF(chan,belle_sip_tls_channel_t)) {
belle_http_provider_t *prov=BELLE_SIP_PROVIDER(obj);
/*
belle_http_provider_t *prov=BELLE_SIP_HTTP_PROVIDER(obj);
belle_sip_auth_event_t* auth_event = belle_sip_auth_event_create(NULL,NULL);
belle_sip_tls_channel_t *tls_chan=BELLE_SIP_TLS_CHANNEL(chan);
auth_event->mode=BELLE_SIP_AUTH_MODE_TLS;
belle_sip_auth_event_set_distinguished_name(auth_event,distinguished_name);
/*
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_auth_requested,auth_event);
belle_sip_tls_channel_set_client_certificates_chain(tls_chan,auth_event->cert);
belle_sip_tls_channel_set_client_certificate_key(tls_chan,auth_event->key);
......@@ -53,26 +59,59 @@ static int channel_on_auth_requested(belle_sip_channel_listener_t *obj, belle_si
}
static void channel_on_sending(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_message_t *msg){
belle_http_channel_context_t *ctx=BELLE_HTTP_CHANNEL_CONTEXT(obj);
ctx->pending_requests=belle_sip_list_append(ctx->pending_requests,msg);
}
static void channel_state_changed(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_channel_state_t state){
switch(state){
case BELLE_SIP_CHANNEL_INIT:
case BELLE_SIP_CHANNEL_RES_IN_PROGRESS:
case BELLE_SIP_CHANNEL_RES_DONE:
case BELLE_SIP_CHANNEL_CONNECTING:
case BELLE_SIP_CHANNEL_READY:
case BELLE_SIP_CHANNEL_RETRY:
break;
case BELLE_SIP_CHANNEL_ERROR:
case BELLE_SIP_CHANNEL_DISCONNECTED:
break;
}
}
static void belle_http_channel_context_uninit(belle_http_channel_context_t *obj){
}
belle_http_channel_context_t * belle_http_channel_context_new(belle_sip_channel_t *chan){
belle_http_channel_context_t *obj=belle_sip_object_new(belle_http_channel_context_t);
belle_sip_channel_add_listener(chan,(belle_sip_channel_listener_t*)obj);
return obj;
}
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_http_provider_t,belle_sip_channel_listener_t)
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_http_channel_context_t,belle_sip_channel_listener_t)
channel_state_changed,
channel_on_event,
channel_on_sending,
channel_on_auth_requested
BELLE_SIP_IMPLEMENT_INTERFACE_END
BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_http_provider_t,belle_sip_channel_listener_t);
BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_http_channel_context_t,belle_sip_channel_listener_t);
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_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_sip_provider_t *belle_http_provider_new(belle_sip_stack_t *s){
belle_sip_provider_t *p=belle_sip_object_new(belle_http_provider_t);
belle_http_provider_t *belle_http_provider_new(belle_sip_stack_t *s){
belle_http_provider_t *p=belle_sip_object_new(belle_http_provider_t);
p->stack=s;
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;*/
belle_http_request_set_listener(req,listener);
}
......@@ -95,7 +95,7 @@ static int belle_sip_headers_container_comp_func(const headers_container_t *a, c
return strcasecmp(a->name,b);
}
static void belle_sip_message_init(belle_sip_message_t *message){
void belle_sip_message_init(belle_sip_message_t *message){
}
......
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