http-listener.c 3.21 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2 3 4 5 6
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2013  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
7
    the Free Software Foundation, either version 2 of the License, or
Simon Morlat's avatar
Simon Morlat committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    (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"


typedef struct belle_http_callbacks belle_http_callbacks_t;

struct belle_http_callbacks{
	belle_sip_object_t base;
	belle_http_request_listener_callbacks_t cbs;
	void *user_ctx;
};

31 32 33 34 35 36
static void process_response_headers(belle_http_request_listener_t *l, const belle_http_response_event_t *event){
	belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
	if (obj->cbs.process_response_headers)
		obj->cbs.process_response_headers(obj->user_ctx,event);
}

Simon Morlat's avatar
Simon Morlat committed
37 38
static void process_response_event(belle_http_request_listener_t *l, const belle_http_response_event_t *event){
	belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
Simon Morlat's avatar
Simon Morlat committed
39 40
	if (obj->cbs.process_response)
		obj->cbs.process_response(obj->user_ctx,event);
Simon Morlat's avatar
Simon Morlat committed
41 42
}

Simon Morlat's avatar
Simon Morlat committed
43
static void process_io_error(belle_http_request_listener_t *l, const belle_sip_io_error_event_t *event){
Simon Morlat's avatar
Simon Morlat committed
44 45 46 47 48
	belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
	if (obj->cbs.process_io_error)
		obj->cbs.process_io_error(obj->user_ctx,event);
}

Simon Morlat's avatar
Simon Morlat committed
49
static void process_timeout(belle_http_request_listener_t *l, const belle_sip_timeout_event_t *event){
Simon Morlat's avatar
Simon Morlat committed
50 51 52 53 54 55 56 57 58 59 60 61 62
	belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
	if (obj->cbs.process_timeout)
		obj->cbs.process_timeout(obj->user_ctx,event);
}

static void process_auth_requested(belle_http_request_listener_t *l, belle_sip_auth_event_t *event){
	belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
	if (obj->cbs.process_auth_requested)
		obj->cbs.process_auth_requested(obj->user_ctx,event);
}



63
/*BELLE_SIP_DECLARE_VPTR(belle_http_callbacks_t);*/
Simon Morlat's avatar
Simon Morlat committed
64 65

BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_http_callbacks_t,belle_http_request_listener_t)
66
	process_response_headers,
Simon Morlat's avatar
Simon Morlat committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	process_response_event,
	process_io_error,
	process_timeout,
	process_auth_requested
BELLE_SIP_IMPLEMENT_INTERFACE_END

BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_http_callbacks_t,belle_http_request_listener_t);

static void belle_http_callbacks_destroy(belle_http_callbacks_t *obj){
	if (obj->cbs.listener_destroyed)
		obj->cbs.listener_destroyed(obj->user_ctx);
}

BELLE_SIP_INSTANCIATE_VPTR(belle_http_callbacks_t,belle_sip_object_t,belle_http_callbacks_destroy,NULL,NULL,FALSE);
	
belle_http_request_listener_t *belle_http_request_listener_create_from_callbacks(const belle_http_request_listener_callbacks_t *callbacks, void *user_ctx){
	belle_http_callbacks_t *obj=belle_sip_object_new(belle_http_callbacks_t);
	memcpy(&obj->cbs,callbacks,sizeof(belle_http_request_listener_callbacks_t));
	obj->user_ctx=user_ctx;
	return BELLE_HTTP_REQUEST_LISTENER(obj);
}