belle_sip_headers_impl.c 4.61 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 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/headers.h"
jehan's avatar
jehan committed
22
#include "belle-sip/parameters.h"
jehan's avatar
jehan committed
23 24 25 26 27 28 29 30 31 32 33 34
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"


/************************
 * header_address
 ***********************/
struct _belle_sip_header_address {
jehan's avatar
jehan committed
35
	belle_sip_parameters_t params;
jehan's avatar
jehan committed
36 37 38
	const char* displayname;
	belle_sip_uri_t* uri;
};
jehan's avatar
jehan committed
39 40 41
static void belle_sip_header_address_init(belle_sip_header_address_t* object){
	belle_sip_object_init_type(object,belle_sip_header_address_t);
	belle_sip_parameters_init((belle_sip_parameters_t*)object); /*super*/
jehan's avatar
jehan committed
42 43
}

jehan's avatar
jehan committed
44 45 46
static void belle_sip_header_address_destroy(belle_sip_header_address_t* contact) {
	if (contact->displayname) belle_sip_free((void*)(contact->displayname));
	if (contact->uri) belle_sip_object_unref(BELLE_SIP_OBJECT(contact->uri));
jehan's avatar
jehan committed
47 48
}

jehan's avatar
jehan committed
49
BELLE_SIP_NEW(header_address,object)
jehan's avatar
jehan committed
50 51
GET_SET_STRING(belle_sip_header_address,displayname);

jehan's avatar
jehan committed
52 53 54 55 56 57
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value) {
		if (address->displayname != NULL) belle_sip_free((void*)(address->displayname));
		size_t value_size = strlen(value);
		address->displayname=belle_sip_malloc0(value_size-2+1);
		strncpy((char*)(address->displayname),value+1,value_size-2);
}
jehan's avatar
jehan committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
belle_sip_uri_t* belle_sip_header_address_get_uri(belle_sip_header_address_t* address) {
	return address->uri;
}

void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri) {
	address->uri=uri;
}



/************************
 * header_contact
 ***********************/
struct _belle_sip_header_contact {
	belle_sip_header_address_t address;
	unsigned int wildcard;
 };

jehan's avatar
jehan committed
76 77
void belle_sip_header_contact_destroy(belle_sip_header_contact_t* contact) {
	belle_sip_header_address_destroy(BELLE_SIP_HEADER_ADDRESS(contact));
jehan's avatar
jehan committed
78 79
}

jehan's avatar
jehan committed
80 81
BELLE_SIP_NEW(header_contact,header_address)
BELLE_SIP_PARSE(header_contact)
jehan's avatar
jehan committed
82

jehan's avatar
jehan committed
83 84
GET_SET_INT_PARAM_PRIVATE(belle_sip_header_contact,expires,int,_)
GET_SET_INT_PARAM_PRIVATE(belle_sip_header_contact,q,float,_);
jehan's avatar
jehan committed
85 86
GET_SET_BOOL(belle_sip_header_contact,wildcard,is);

jehan's avatar
jehan committed
87

jehan's avatar
jehan committed
88 89 90 91 92 93 94 95
int belle_sip_header_contact_set_expires(belle_sip_header_contact_t* contact, int expires) {
	if (expires < 0 ) {
		return -1;
	}
	_belle_sip_header_contact_set_expires(contact,expires);
	return 0;
 }
int belle_sip_header_contact_set_qvalue(belle_sip_header_contact_t* contact, float qValue) {
jehan's avatar
jehan committed
96
	 if (qValue != -1 && qValue < 0 && qValue >1) {
jehan's avatar
jehan committed
97 98
		 return -1;
	 }
jehan's avatar
jehan committed
99
	 _belle_sip_header_contact_set_q(contact,qValue);
jehan's avatar
jehan committed
100 101
	 return 0;
}
jehan's avatar
jehan committed
102 103 104 105
float	belle_sip_header_contact_get_qvalue(belle_sip_header_contact_t* contact) {
	return belle_sip_header_contact_get_q(contact);
}
/**************************
jehan's avatar
jehan committed
106
* From header object inherent from header_address
jehan's avatar
jehan committed
107
****************************
jehan's avatar
jehan committed
108 109 110 111 112
*/
struct _belle_sip_header_from  {
	belle_sip_header_address_t address;
};

jehan's avatar
jehan committed
113 114 115 116 117
static void belle_sip_header_from_destroy(belle_sip_header_from_t* from) {
	belle_sip_header_address_destroy(BELLE_SIP_HEADER_ADDRESS(from));
}

BELLE_SIP_NEW(header_from,header_address)
jehan's avatar
jehan committed
118
BELLE_SIP_PARSE(header_from)
jehan's avatar
jehan committed
119 120 121 122 123 124 125 126 127
GET_SET_STRING_PARAM(belle_sip_header_from,tag);

/**************************
* To header object inherent from header_address
****************************
*/
struct _belle_sip_header_to  {
	belle_sip_header_address_t address;
};
jehan's avatar
jehan committed
128

jehan's avatar
jehan committed
129 130
static void belle_sip_header_to_destroy(belle_sip_header_to_t* to) {
	belle_sip_header_address_destroy(BELLE_SIP_HEADER_ADDRESS(to));
jehan's avatar
jehan committed
131
}
jehan's avatar
jehan committed
132

jehan's avatar
jehan committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
BELLE_SIP_NEW(header_to,header_address)
BELLE_SIP_PARSE(header_to)
GET_SET_STRING_PARAM(belle_sip_header_to,tag);
/**************************
* Viq header object inherent from header_address
****************************
*/
struct _belle_sip_header_via  {
	belle_sip_header_address_t address;
};

static void belle_sip_header_via_destroy(belle_sip_header_via_t* to) {
	belle_sip_header_address_destroy(BELLE_SIP_HEADER_ADDRESS(to));
}

BELLE_SIP_NEW(header_via,header_address)
BELLE_SIP_PARSE(header_via)

jehan's avatar
jehan committed
151 152 153