provider.c 3.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/*
	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"



static int listener_ctx_compare(const void *c1, const void *c2){
	listener_ctx_t *lc1=(listener_ctx_t*)c1;
	listener_ctx_t *lc2=(listener_ctx_t*)c2;
	return !(lc1->listener==lc2->listener && lc1->data==lc2->data);
}


static void belle_sip_provider_uninit(belle_sip_provider_t *p){
	belle_sip_list_for_each (p->listeners,belle_sip_free);
	belle_sip_list_free(p->listeners);
	belle_sip_list_free(p->lps);
}

belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp){
	belle_sip_provider_t *p=belle_sip_object_new(belle_sip_provider_t,belle_sip_provider_uninit);
	belle_sip_provider_add_listening_point(p,lp);
	return p;
}

int belle_sip_provider_add_listening_point(belle_sip_provider_t *p, belle_sip_listening_point_t *lp){
	p->lps=belle_sip_list_append(p->lps,lp);
	return 0;
}

belle_sip_listening_point_t *belle_sip_provider_get_listening_point(belle_sip_provider_t *p, const char *transport){
	belle_sip_list_t *l;
	for(l=p->lps;l!=NULL;l=l->next){
		belle_sip_listening_point_t *lp=(belle_sip_listening_point_t*)l->data;
		if (strcasecmp(belle_sip_listening_point_get_transport(lp),transport)==0)
			return lp;
	}
	return NULL;
}

const belle_sip_list_t *belle_sip_provider_get_listening_points(belle_sip_provider_t *p){
	return p->lps;
}

void belle_sip_provider_add_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, void *user_ctx){
	listener_ctx_t *lc=belle_sip_new(listener_ctx_t);
	lc->listener=l;
	lc->data=user_ctx;
	p->listeners=belle_sip_list_append(p->listeners,lc);
}

void belle_sip_provider_remove_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, void *user_ctx){
	listener_ctx_t ctx={l,user_ctx};
	p->listeners=belle_sip_list_remove_custom(p->listeners,listener_ctx_compare,&ctx);
}

belle_sip_client_transaction_t *belle_sip_provider_create_client_transaction(belle_sip_provider_t *p, belle_sip_request_t *req){
	return belle_sip_client_transaction_new(p,req);
}

belle_sip_server_transaction_t *belle_sip_provider_create_server_transaction(belle_sip_provider_t *p, belle_sip_request_t *req){
	return belle_sip_server_transaction_new(p,req);
}

belle_sip_stack_t *belle_sip_provider_get_sip_stack(belle_sip_provider_t *p){
	return p->stack;
}

Simon Morlat's avatar
wip  
Simon Morlat committed
85 86 87 88 89 90 91
static void sender_task_cb(belle_sip_sender_task_t *t, void *data, int retcode){
	if (retcode!=0){
		/*would need to notify the application of the failure */
	}
	belle_sip_object_unref(t);
}

92
void belle_sip_provider_send_request(belle_sip_provider_t *p, belle_sip_request_t *req){
Simon Morlat's avatar
wip  
Simon Morlat committed
93
	belle_sip_sender_task_t *task;
Simon Morlat's avatar
Simon Morlat committed
94

Simon Morlat's avatar
wip  
Simon Morlat committed
95 96
	task=belle_sip_sender_task_new(p, BELLE_SIP_MESSAGE(req), sender_task_cb, NULL);
	belle_sip_sender_task_send(task);
97 98
}

Simon Morlat's avatar
wip  
Simon Morlat committed
99 100 101 102 103 104
void belle_sip_provider_send_response(belle_sip_provider_t *p, belle_sip_response_t *resp){
	belle_sip_sender_task_t *task;

	task=belle_sip_sender_task_new(p, BELLE_SIP_MESSAGE(resp), sender_task_cb, NULL);
	belle_sip_sender_task_send(task);
}
105