siplistener.c 5.98 KB
Newer Older
1 2 3 4 5 6
/*
	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
7
    the Free Software Foundation, either version 2 of the License, or
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    (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"


belle_sip_response_t* belle_sip_response_event_get_response(const belle_sip_response_event_t* event) {
	return event->response;
}

belle_sip_client_transaction_t *belle_sip_response_event_get_client_transaction(const belle_sip_response_event_t* event){
	return event->client_transaction;
}

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
belle_sip_dialog_t *belle_sip_response_event_get_dialog(const belle_sip_response_event_t* event){
	return event->dialog;
}

belle_sip_request_t* belle_sip_request_event_get_request(const belle_sip_request_event_t* event){
	return event->request;
}

belle_sip_server_transaction_t *belle_sip_request_event_get_server_transaction(const belle_sip_request_event_t* event){
	return event->server_transaction;
}

belle_sip_dialog_t *belle_sip_request_event_get_dialog(const belle_sip_request_event_t* event){
	return event->dialog;
}

Simon Morlat's avatar
Simon Morlat committed
45
belle_sip_dialog_t* belle_sip_dialog_terminated_event_get_dialog(const belle_sip_dialog_terminated_event_t *event) {
46 47
	return event->dialog;
}
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
const char* belle_sip_io_error_event_get_host(const belle_sip_io_error_event_t* event) {
	return event->host;
}

const char* belle_sip_io_error_event_get_transport(const belle_sip_io_error_event_t* event) {
	return event->transport;
}

unsigned int belle_sip_io_error_event_port(const belle_sip_io_error_event_t* event) {
	return event->port;
}

belle_sip_object_t* belle_sip_io_error_event_get_source(const belle_sip_io_error_event_t* event) {
	return event->source;
}

jehan's avatar
jehan committed
65

jehan's avatar
jehan committed
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
typedef struct belle_sip_callbacks belle_sip_callbacks_t;

struct belle_sip_callbacks{
	belle_sip_object_t base;
	belle_sip_listener_callbacks_t cbs;
	void *user_ctx;
};


static void process_dialog_terminated(belle_sip_listener_t *l, const belle_sip_dialog_terminated_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_dialog_terminated)
		obj->cbs.process_dialog_terminated(obj->user_ctx,event);
}

static void process_io_error(belle_sip_listener_t *l, const belle_sip_io_error_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_io_error)
		obj->cbs.process_io_error(obj->user_ctx,event);
}

static void process_request_event(belle_sip_listener_t *l, const belle_sip_request_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_request_event)
		obj->cbs.process_request_event(obj->user_ctx,event);
}

static void process_response_event(belle_sip_listener_t *l, const belle_sip_response_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_response_event)
		obj->cbs.process_response_event(obj->user_ctx,event);
}

static void process_timeout(belle_sip_listener_t *l, const belle_sip_timeout_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_timeout)
		obj->cbs.process_timeout(obj->user_ctx,event);
}

static void process_transaction_terminated(belle_sip_listener_t *l, const belle_sip_transaction_terminated_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_transaction_terminated)
		obj->cbs.process_transaction_terminated(obj->user_ctx,event);
}
jehan's avatar
jehan committed
111 112 113 114 115
static void process_auth_requested(belle_sip_listener_t *l, belle_sip_auth_event_t *event){
	belle_sip_callbacks_t *obj=(belle_sip_callbacks_t*)l;
	if (obj->cbs.process_auth_requested)
		obj->cbs.process_auth_requested(obj->user_ctx,event);
}
116 117 118 119 120 121 122 123 124

BELLE_SIP_DECLARE_VPTR(belle_sip_callbacks_t);

BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(belle_sip_callbacks_t,belle_sip_listener_t)
	process_dialog_terminated,
	process_io_error,
	process_request_event,
	process_response_event,
	process_timeout,
jehan's avatar
jehan committed
125 126
	process_transaction_terminated,
	process_auth_requested
127 128 129 130
BELLE_SIP_IMPLEMENT_INTERFACE_END

BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(belle_sip_callbacks_t,belle_sip_listener_t);

Simon Morlat's avatar
Simon Morlat committed
131 132 133 134 135 136
static void belle_sip_callbacks_destroy(belle_sip_callbacks_t *obj){
	if (obj->cbs.listener_destroyed)
		obj->cbs.listener_destroyed(obj->user_ctx);
}

BELLE_SIP_INSTANCIATE_VPTR(belle_sip_callbacks_t,belle_sip_object_t,belle_sip_callbacks_destroy,NULL,NULL,FALSE);
137 138 139 140 141 142 143 144 145


belle_sip_listener_t *belle_sip_listener_create_from_callbacks(const belle_sip_listener_callbacks_t *callbacks, void *user_ctx){
	belle_sip_callbacks_t *obj=belle_sip_object_new(belle_sip_callbacks_t);
	memcpy(&obj->cbs,callbacks,sizeof(belle_sip_listener_callbacks_t));
	obj->user_ctx=user_ctx;
	return BELLE_SIP_LISTENER(obj);
}

jehan's avatar
jehan committed
146 147 148 149 150 151 152 153 154 155 156 157 158
belle_sip_client_transaction_t *belle_sip_transaction_terminated_event_get_client_transaction(const belle_sip_transaction_terminated_event_t* event) {
	return event->is_server_transaction ? NULL:BELLE_SIP_CLIENT_TRANSACTION(event->transaction);
}
belle_sip_server_transaction_t *belle_sip_transaction_terminated_event_get_server_transaction(const belle_sip_transaction_terminated_event_t* event) {
	return event->is_server_transaction ? BELLE_SIP_SERVER_TRANSACTION(event->transaction):NULL;
}

belle_sip_client_transaction_t *belle_sip_timeout_event_get_client_transaction(const belle_sip_timeout_event_t* event) {
	return event->is_server_transaction ? NULL:BELLE_SIP_CLIENT_TRANSACTION(event->transaction);
}
belle_sip_server_transaction_t *belle_sip_timeout_event_get_server_transaction(const belle_sip_timeout_event_t* event) {
	return event->is_server_transaction ? BELLE_SIP_SERVER_TRANSACTION(event->transaction):NULL;
}