http-provider.c 4.24 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
	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"

Simon Morlat's avatar
Simon Morlat committed
22 23 24 25 26 27 28 29
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;
};
Simon Morlat's avatar
Simon Morlat committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

struct belle_http_provider{
	belle_sip_stack_t *stack;
	belle_sip_list_t *tcp_channels;
	belle_sip_list_t *tls_channels;
};

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){
	}
	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)) {
Simon Morlat's avatar
Simon Morlat committed
45 46
		/*
		belle_http_provider_t *prov=BELLE_SIP_HTTP_PROVIDER(obj);
Simon Morlat's avatar
Simon Morlat committed
47 48 49 50
		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);
Simon Morlat's avatar
Simon Morlat committed
51
		
Simon Morlat's avatar
Simon Morlat committed
52 53 54 55 56 57 58 59 60 61
		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);
		belle_sip_auth_event_destroy(auth_event);
		*/
	}
	return 0;
}

static void channel_on_sending(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, belle_sip_message_t *msg){
Simon Morlat's avatar
Simon Morlat committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	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;
	}
Simon Morlat's avatar
Simon Morlat committed
79 80
}

Simon Morlat's avatar
Simon Morlat committed
81 82 83 84 85 86 87 88
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;
}
Simon Morlat's avatar
Simon Morlat committed
89

Simon Morlat's avatar
Simon Morlat committed
90
BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_http_channel_context_t,belle_sip_channel_listener_t)
Simon Morlat's avatar
Simon Morlat committed
91 92 93 94 95 96
	channel_state_changed,
	channel_on_event,
	channel_on_sending,
	channel_on_auth_requested
BELLE_SIP_IMPLEMENT_INTERFACE_END

Simon Morlat's avatar
Simon Morlat committed
97 98
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);
Simon Morlat's avatar
Simon Morlat committed
99 100 101 102

static void http_provider_uninit(belle_http_provider_t *obj){
}

Simon Morlat's avatar
Simon Morlat committed
103
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_http_provider_t);
Simon Morlat's avatar
Simon Morlat committed
104 105
BELLE_SIP_INSTANCIATE_VPTR(belle_http_provider_t,belle_sip_object_t,http_provider_uninit,NULL,NULL,FALSE);

Simon Morlat's avatar
Simon Morlat committed
106 107
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);
Simon Morlat's avatar
Simon Morlat committed
108 109 110
	p->stack=s;
	return p;
}
Simon Morlat's avatar
Simon Morlat committed
111 112 113 114 115 116 117

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);
	
}