belle_sip_parameters.c 4.03 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	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/belle-sip.h"
#include "belle-sip/parameters.h"
#include "belle_sip_internal.h"
jehan's avatar
jehan committed
21
#include "belle-sip/headers.h"
jehan's avatar
jehan committed
22

Simon Morlat's avatar
Simon Morlat committed
23 24 25 26
void belle_sip_parameters_init(belle_sip_parameters_t *obj){
}

static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
jehan's avatar
jehan committed
27 28 29 30
	if (params->param_list) belle_sip_list_free (params->param_list);
	if (params->paramnames_list) belle_sip_list_free (params->paramnames_list);
}

Simon Morlat's avatar
Simon Morlat committed
31 32
static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const belle_sip_parameters_t *orig){
	belle_sip_fatal("not implemented");
jehan's avatar
jehan committed
33
}
jehan's avatar
jehan committed
34 35 36 37 38 39 40 41 42 43 44 45 46
int belle_sip_parameters_marshal(belle_sip_parameters_t* params, char* buff,unsigned int offset,unsigned int buff_size) {
	belle_sip_list_t* list=params->param_list;
	unsigned int curent_offset=offset;
	for(;list!=NULL;list=list->next){
		belle_sip_param_pair_t* container = (belle_sip_param_pair_t* )(list->data);
		if (container->value) {
			curent_offset+=snprintf(buff+curent_offset,buff_size-curent_offset,";%s=%s",container->name,container->value);
		} else {
			curent_offset+=snprintf(buff+curent_offset,buff_size-curent_offset,";%s",container->name);
		}
	}
	return curent_offset-offset;
}
Simon Morlat's avatar
Simon Morlat committed
47
BELLE_SIP_NEW(parameters,header)
jehan's avatar
jehan committed
48 49 50
const belle_sip_list_t *	belle_sip_parameters_get_parameters(belle_sip_parameters_t* obj) {
	return obj->param_list;
}
jehan's avatar
jehan committed
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 85 86 87 88 89 90 91 92 93 94 95
const char*	belle_sip_parameters_get_parameter(belle_sip_parameters_t* params,const char* name) {
	belle_sip_list_t *  lResult = belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name);
	if (lResult) {
		return ((belle_sip_param_pair_t*)(lResult->data))->value;
	}
	else {
		return NULL;
	}
}
unsigned int belle_sip_parameters_is_parameter(belle_sip_parameters_t* params,const char* name) {
	return belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name) != NULL;
}
void	belle_sip_parameters_set_parameter(belle_sip_parameters_t* params,const char* name,const char* value) {
	/*1 check if present*/
	belle_sip_list_t *  lResult = belle_sip_list_find_custom(params->paramnames_list, (belle_sip_compare_func)strcmp, name);
	/* first remove from header names list*/
	if (lResult) {
		belle_sip_list_remove_link(params->paramnames_list,lResult);
	}
	/* next from header list*/
	lResult = belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name);
	if (lResult) {
		belle_sip_param_pair_destroy(lResult->data);
		belle_sip_list_remove_link(params->param_list,lResult);
	}
	/* 2 insert*/
	belle_sip_param_pair_t* lNewpair = belle_sip_param_pair_new(name,value);
	params->param_list=belle_sip_list_append(params->param_list,lNewpair);
	params->paramnames_list=belle_sip_list_append(params->paramnames_list,lNewpair->name);
}

const belle_sip_list_t*	belle_sip_parameters_get_parameter_names(belle_sip_parameters_t* params) {
	return params->paramnames_list;
}
void	belle_sip_parameters_remove_parameter(belle_sip_parameters_t* params,const char* name) {
	/*1 check if present*/
	belle_sip_list_t *  lResult = belle_sip_list_find_custom(params->paramnames_list, (belle_sip_compare_func)strcmp, name);
	/* first remove from header names list*/
	if (lResult) {
		belle_sip_list_remove_link(params->paramnames_list,lResult);
	} else {
		belle_sip_warning("cannot remove param \%s because not present",name);
	}
}