belle_sip_headers_impl.c 59.7 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
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "belle_sip_messageParser.h"
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"
jehan's avatar
jehan committed
29
#include "listeningpoint_internal.h"
jehan's avatar
jehan committed
30

jehan's avatar
jehan committed
31 32 33
/************************
 * header
 ***********************/
jehan's avatar
jehan committed
34

jehan's avatar
jehan committed
35
GET_SET_STRING(belle_sip_header,name);
36

jehan's avatar
jehan committed
37 38 39
belle_sip_header_t* belle_sip_header_create (const char* name,const char* value) {
	return BELLE_SIP_HEADER(belle_sip_header_extension_create(name,value));
}
Simon Morlat's avatar
Simon Morlat committed
40

jehan's avatar
jehan committed
41
void belle_sip_header_init(belle_sip_header_t *header) {
Simon Morlat's avatar
Simon Morlat committed
42

jehan's avatar
jehan committed
43
}
Simon Morlat's avatar
Simon Morlat committed
44

45
static void belle_sip_header_clone(belle_sip_header_t *header, const belle_sip_header_t *orig){
46
	CLONE_STRING(belle_sip_header,name,header,orig)
47
	if (belle_sip_header_get_next(orig)) {
48
		belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ;
49 50
	}
}
Simon Morlat's avatar
Simon Morlat committed
51

Simon Morlat's avatar
Simon Morlat committed
52
static void belle_sip_header_destroy(belle_sip_header_t *header){
Simon Morlat's avatar
Simon Morlat committed
53 54
	if (header->name) belle_sip_free(header->name);
	if (header->unparsed_value) belle_sip_free(header->unparsed_value);
jehan's avatar
jehan committed
55 56
	if (header->next) belle_sip_object_unref(BELLE_SIP_OBJECT(header->next));
}
Simon Morlat's avatar
Simon Morlat committed
57

jehan's avatar
jehan committed
58
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next) {
59 60
	if (next) belle_sip_object_ref(next);
	if(header->next) belle_sip_object_unref(header->next);
jehan's avatar
jehan committed
61 62
	header->next = next;
}
Simon Morlat's avatar
Simon Morlat committed
63

jehan's avatar
jehan committed
64 65
belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* header) {
	return header->next;
jehan's avatar
jehan committed
66
}
jehan's avatar
jehan committed
67

Simon Morlat's avatar
Simon Morlat committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
const char *belle_sip_header_get_unparsed_value(belle_sip_header_t* obj){
	char *tmp=belle_sip_object_to_string(obj);
	char *ret;
	char *end;
	if (obj->unparsed_value){
		belle_sip_free(obj->unparsed_value);
		obj->unparsed_value=NULL;
	}
	obj->unparsed_value=tmp;
	ret=tmp;
	ret+=strlen(obj->name)+1; /* name + semicolon*/
	for(;*ret==' ';ret++){};/*skip spaces*/
	end=strchr(ret,'\r');
	if (end) *end='\0'; /*remove \r\n*/
	return ret;
}

85
belle_sip_error_code belle_sip_header_marshal(belle_sip_header_t* header, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
86
	if (header->name) {
Ghislain MARY's avatar
Ghislain MARY committed
87
		return belle_sip_snprintf(buff,buff_size,offset,"%s: ",header->name);
jehan's avatar
jehan committed
88 89
	} else {
		belle_sip_warning("no header name found");
Ghislain MARY's avatar
Ghislain MARY committed
90
		return BELLE_SIP_OK;
jehan's avatar
jehan committed
91 92
	}
}
93 94 95

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_header_t);

Simon Morlat's avatar
Simon Morlat committed
96
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_header_t,belle_sip_object_t,belle_sip_header_destroy,belle_sip_header_clone,belle_sip_header_marshal,TRUE);
Simon Morlat's avatar
Simon Morlat committed
97 98


jehan's avatar
jehan committed
99 100 101 102
/************************
 * header_address
 ***********************/
struct _belle_sip_header_address {
Simon Morlat's avatar
Simon Morlat committed
103
	belle_sip_parameters_t base;
Simon Morlat's avatar
Simon Morlat committed
104
	char* displayname;
jehan's avatar
jehan committed
105 106
	belle_sip_uri_t* uri;
};
Simon Morlat's avatar
Simon Morlat committed
107

jehan's avatar
jehan committed
108 109
static void belle_sip_header_address_init(belle_sip_header_address_t* object){
	belle_sip_parameters_init((belle_sip_parameters_t*)object); /*super*/
jehan's avatar
jehan committed
110 111
}

jehan's avatar
jehan committed
112
static void belle_sip_header_address_destroy(belle_sip_header_address_t* address) {
Simon Morlat's avatar
Simon Morlat committed
113 114
	if (address->displayname) belle_sip_free(address->displayname);
	if (address->uri) belle_sip_object_unref(address->uri);
jehan's avatar
jehan committed
115 116
}

117
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
118 119 120 121
	CLONE_STRING(belle_sip_header_address,displayname,addr,orig)
	if (belle_sip_header_address_get_uri(orig)) {
		belle_sip_header_address_set_uri(addr,BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(orig)))));
	}
Simon Morlat's avatar
Simon Morlat committed
122
}
123

124
belle_sip_error_code belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
125
	belle_sip_error_code error=BELLE_SIP_OK;
jehan's avatar
jehan committed
126 127
	/*1 display name*/
	if (header->displayname) {
Ghislain MARY's avatar
Ghislain MARY committed
128 129
		error=belle_sip_snprintf(buff,buff_size,offset,"\"%s\" ",header->displayname);
		if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
130 131
	}
	if (header->uri) {
132 133 134 135 136
		/*cases where < is required*/
		if (header->displayname
			|| belle_sip_parameters_get_parameter_names((belle_sip_parameters_t*)header->uri)
			|| belle_sip_uri_get_header_names(header->uri)
			|| belle_sip_parameters_get_parameter_names(&header->base)) {
Ghislain MARY's avatar
Ghislain MARY committed
137 138
			error=belle_sip_snprintf(buff,buff_size,offset,"%s","<");
			if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
139
		}
Ghislain MARY's avatar
Ghislain MARY committed
140 141
		error=belle_sip_uri_marshal(header->uri,buff,buff_size,offset);
		if (error!=BELLE_SIP_OK) return error;
142 143 144 145
		if (header->displayname
				|| belle_sip_parameters_get_parameter_names((belle_sip_parameters_t*)header->uri)
				|| belle_sip_uri_get_header_names(header->uri)
				|| belle_sip_parameters_get_parameter_names(&header->base)) {
Ghislain MARY's avatar
Ghislain MARY committed
146 147
			error=belle_sip_snprintf(buff,buff_size,offset,"%s",">");
			if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
148 149
		}
	}
Ghislain MARY's avatar
Ghislain MARY committed
150 151 152
	error=belle_sip_parameters_marshal(&header->base,buff,buff_size,offset);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
153
}
Simon Morlat's avatar
Simon Morlat committed
154

155
BELLE_SIP_NEW_HEADER(header_address,parameters,"header_address")
jehan's avatar
jehan committed
156
BELLE_SIP_PARSE(header_address)
jehan's avatar
jehan committed
157 158
GET_SET_STRING(belle_sip_header_address,displayname);

jehan's avatar
jehan committed
159
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value) {
Simon Morlat's avatar
Simon Morlat committed
160
		if (address->displayname != NULL) belle_sip_free(address->displayname);
jehan's avatar
jehan committed
161 162 163 164
		if (strlen(value)>2)
			address->displayname=_belle_sip_str_dup_and_unquote_string(value);
		else
			address->displayname=NULL;
jehan's avatar
jehan committed
165
}
Simon Morlat's avatar
Simon Morlat committed
166

167
belle_sip_uri_t* belle_sip_header_address_get_uri(const belle_sip_header_address_t* address) {
jehan's avatar
jehan committed
168 169 170 171
	return address->uri;
}

void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri) {
Simon Morlat's avatar
Simon Morlat committed
172 173 174 175 176
	belle_sip_object_ref(uri);
	if (address->uri){
		belle_sip_object_unref(address->uri);
	}
	address->uri=uri;
jehan's avatar
jehan committed
177 178
}

jehan's avatar
jehan committed
179 180 181 182 183 184
belle_sip_header_address_t* belle_sip_header_address_create(const char* display, belle_sip_uri_t* uri) {
	belle_sip_header_address_t* address = belle_sip_header_address_new();
	belle_sip_header_address_set_displayname(address,display);
	belle_sip_header_address_set_uri(address,uri);
	return address;
}
jehan's avatar
jehan committed
185

jehan's avatar
jehan committed
186
/******************************
187
 * Extension header inherits from header
jehan's avatar
jehan committed
188 189 190 191 192 193
 *
 ******************************/
struct _belle_sip_header_allow  {
	belle_sip_header_t header;
	const char* method;
};
194 195 196
static void belle_sip_header_allow_clone(belle_sip_header_allow_t *allow, const belle_sip_header_allow_t *orig){
	CLONE_STRING(belle_sip_header_allow,method,allow,orig)
}
jehan's avatar
jehan committed
197 198 199 200
static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) {
	if (allow->method) belle_sip_free((void*)allow->method);
}

201

202
belle_sip_error_code belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
203 204 205 206 207
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%s",allow->method);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
208
}
Ghislain MARY's avatar
Ghislain MARY committed
209

jehan's avatar
jehan committed
210 211
BELLE_SIP_NEW_HEADER(header_allow,header,"Allow")
BELLE_SIP_PARSE(header_allow)
jehan's avatar
jehan committed
212 213 214 215 216
belle_sip_header_allow_t* belle_sip_header_allow_create (const char* methods) {
	belle_sip_header_allow_t* allow = belle_sip_header_allow_new();
	belle_sip_header_allow_set_method(allow,methods);
	return allow;
}
jehan's avatar
jehan committed
217 218 219
GET_SET_STRING(belle_sip_header_allow,method);


jehan's avatar
jehan committed
220 221 222 223 224 225

/************************
 * header_contact
 ***********************/
struct _belle_sip_header_contact {
	belle_sip_header_address_t address;
226 227
	unsigned char wildcard;
	unsigned char automatic;
228 229
	unsigned char unknown;
	unsigned char pad[1];
jehan's avatar
jehan committed
230 231
 };

jehan's avatar
jehan committed
232
void belle_sip_header_contact_destroy(belle_sip_header_contact_t* contact) {
Simon Morlat's avatar
Simon Morlat committed
233 234 235
}

void belle_sip_header_contact_clone(belle_sip_header_contact_t *contact, const belle_sip_header_contact_t *orig){
236
	contact->wildcard=orig->wildcard;
237
	contact->automatic=orig->automatic;
jehan's avatar
jehan committed
238
}
Ghislain MARY's avatar
Ghislain MARY committed
239

240
belle_sip_error_code belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
241 242
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(contact), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
243
	if (contact->wildcard) {
Ghislain MARY's avatar
Ghislain MARY committed
244
		error=belle_sip_snprintf(buff,buff_size,offset,"%s","*");
jehan's avatar
jehan committed
245
	} else {
Ghislain MARY's avatar
Ghislain MARY committed
246
		error=belle_sip_header_address_marshal(&contact->address, buff, buff_size, offset);
jehan's avatar
jehan committed
247
	}
Ghislain MARY's avatar
Ghislain MARY committed
248
	return error;
jehan's avatar
jehan committed
249
}
Ghislain MARY's avatar
Ghislain MARY committed
250

jehan's avatar
jehan committed
251
BELLE_SIP_NEW_HEADER(header_contact,header_address,BELLE_SIP_CONTACT)
jehan's avatar
jehan committed
252
BELLE_SIP_PARSE(header_contact)
jehan's avatar
jehan committed
253 254
belle_sip_header_contact_t* belle_sip_header_contact_create (const belle_sip_header_address_t* contact) {
	belle_sip_header_contact_t* header = belle_sip_header_contact_new();
jehan's avatar
jehan committed
255 256
	_belle_sip_object_copy(BELLE_SIP_OBJECT(header),BELLE_SIP_OBJECT(contact));
	belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_CONTACT); /*restaure header name*/
jehan's avatar
jehan committed
257 258
	return header;
}
jehan's avatar
jehan committed
259 260
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
261 262
GET_SET_BOOL(belle_sip_header_contact,wildcard,is);

jehan's avatar
jehan committed
263

jehan's avatar
jehan committed
264 265
int belle_sip_header_contact_set_expires(belle_sip_header_contact_t* contact, int expires) {
	if (expires < 0 ) {
266
		 belle_sip_error("bad expires value [%i] for contact",expires);
jehan's avatar
jehan committed
267 268 269 270 271 272
		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
273
	 if (qValue != -1 && qValue < 0 && qValue >1) {
274
		 belle_sip_error("bad q value [%f] for contact",qValue);
jehan's avatar
jehan committed
275 276
		 return -1;
	 }
jehan's avatar
jehan committed
277
	 _belle_sip_header_contact_set_q(contact,qValue);
jehan's avatar
jehan committed
278 279
	 return 0;
}
280
float	belle_sip_header_contact_get_qvalue(const belle_sip_header_contact_t* contact) {
jehan's avatar
jehan committed
281 282
	return belle_sip_header_contact_get_q(contact);
}
jehan's avatar
jehan committed
283 284
unsigned int belle_sip_header_contact_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
	if (!a | !b) return 0;
285
	return belle_sip_uri_equals(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(a))
jehan's avatar
jehan committed
286 287
								,belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(b)));
}
288 289 290
unsigned int belle_sip_header_contact_not_equals(const belle_sip_header_contact_t* a,const belle_sip_header_contact_t* b) {
	return !belle_sip_header_contact_equals(a,b);
}
291 292 293 294 295 296 297 298

void belle_sip_header_contact_set_automatic(belle_sip_header_contact_t *a, int enabled){
	a->automatic=enabled;
}
 
int belle_sip_header_contact_get_automatic(const belle_sip_header_contact_t *a){
	return a->automatic;
}
299 300 301 302 303 304 305 306

void belle_sip_header_contact_set_unknown(belle_sip_header_contact_t *a, int value){
	a->unknown=value;
}

int belle_sip_header_contact_is_unknown(const belle_sip_header_contact_t *a){
	return a->unknown;
}
jehan's avatar
jehan committed
307
/**************************
jehan's avatar
jehan committed
308
* From header object inherent from header_address
jehan's avatar
jehan committed
309
****************************
jehan's avatar
jehan committed
310
*/
jehan's avatar
jehan committed
311
#define BELLE_SIP_FROM_LIKE_MARSHAL(header) \
Ghislain MARY's avatar
Ghislain MARY committed
312 313 314 315 316
		belle_sip_error_code error=belle_sip_##header_marshal(BELLE_SIP_HEADER(header), buff, buff_size, offset);\
		if (error!=BELLE_SIP_OK) return error;\
		error=belle_sip_header_address_marshal(&header->address, buff, buff_size, offset); \
		if (error!=BELLE_SIP_OK) return error;\
		return error;
317

jehan's avatar
jehan committed
318 319 320 321
struct _belle_sip_header_from  {
	belle_sip_header_address_t address;
};

jehan's avatar
jehan committed
322 323 324
static void belle_sip_header_from_destroy(belle_sip_header_from_t* from) {
}

Simon Morlat's avatar
Simon Morlat committed
325 326
static void belle_sip_header_from_clone(belle_sip_header_from_t* from, const belle_sip_header_from_t* cloned) {
}
Simon Morlat's avatar
Simon Morlat committed
327

328
belle_sip_error_code belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
329 330
	BELLE_SIP_FROM_LIKE_MARSHAL(from);
}
Simon Morlat's avatar
Simon Morlat committed
331

jehan's avatar
jehan committed
332
belle_sip_header_from_t* belle_sip_header_from_create2(const char *address, const char *tag){
333 334
	char *tmp=belle_sip_strdup_printf("From: %s",address);
	belle_sip_header_from_t *from=belle_sip_header_from_parse(tmp);
335
	if (from){
336
		if (tag) belle_sip_header_from_set_tag(from,tag);
337
	}
338 339 340
	belle_sip_free(tmp);
	return from;
}
jehan's avatar
jehan committed
341 342
belle_sip_header_from_t* belle_sip_header_from_create(const belle_sip_header_address_t* address, const char *tag) {
	belle_sip_header_from_t* header= belle_sip_header_from_new();
Simon Morlat's avatar
Simon Morlat committed
343
	_belle_sip_object_copy((belle_sip_object_t*)header,(belle_sip_object_t*)address);
Simon Morlat's avatar
Simon Morlat committed
344
	belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_FROM); /*restore header name*/
345
	if (tag) belle_sip_header_from_set_tag(header,tag);
jehan's avatar
jehan committed
346 347
	return header;
}
jehan's avatar
jehan committed
348
BELLE_SIP_NEW_HEADER(header_from,header_address,BELLE_SIP_FROM)
jehan's avatar
jehan committed
349
BELLE_SIP_PARSE(header_from)
350
GET_SET_STRING_PARAM2(belle_sip_header_from,tag,raw_tag);
jehan's avatar
jehan committed
351

352
void belle_sip_header_from_set_random_tag(belle_sip_header_from_t *obj){
Simon Morlat's avatar
Simon Morlat committed
353
	char tmp[BELLE_SIP_TAG_LENGTH];
354 355 356 357 358 359 360 361 362 363
	belle_sip_header_from_set_raw_tag(obj,belle_sip_random_token(tmp,sizeof(tmp)));
}

void belle_sip_header_from_set_tag(belle_sip_header_from_t *obj, const char *tag){
	if (tag==BELLE_SIP_RANDOM_TAG) belle_sip_header_from_set_random_tag(obj);
	else belle_sip_header_from_set_raw_tag(obj,tag);
}

const char *belle_sip_header_from_get_tag(const belle_sip_header_from_t *obj){
	return belle_sip_header_from_get_raw_tag(obj);
364 365
}

jehan's avatar
jehan committed
366
/**************************
Simon Morlat's avatar
Simon Morlat committed
367
* To header object inherits from header_address
jehan's avatar
jehan committed
368 369 370 371 372
****************************
*/
struct _belle_sip_header_to  {
	belle_sip_header_address_t address;
};
jehan's avatar
jehan committed
373

jehan's avatar
jehan committed
374
static void belle_sip_header_to_destroy(belle_sip_header_to_t* to) {
Simon Morlat's avatar
Simon Morlat committed
375 376 377
}

void belle_sip_header_to_clone(belle_sip_header_to_t *contact, const belle_sip_header_to_t *orig){
jehan's avatar
jehan committed
378
}
Ghislain MARY's avatar
Ghislain MARY committed
379

380
belle_sip_error_code belle_sip_header_to_marshal(belle_sip_header_to_t* to, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
381 382
	BELLE_SIP_FROM_LIKE_MARSHAL(to)
}
jehan's avatar
jehan committed
383

jehan's avatar
fix tag  
jehan committed
384
BELLE_SIP_NEW_HEADER(header_to,header_address,BELLE_SIP_TO)
jehan's avatar
jehan committed
385
BELLE_SIP_PARSE(header_to)
386
GET_SET_STRING_PARAM2(belle_sip_header_to,tag,raw_tag);
387

jehan's avatar
jehan committed
388
belle_sip_header_to_t* belle_sip_header_to_create2(const char *address, const char *tag){
389 390
	char *tmp=belle_sip_strdup_printf("To: %s",address);
	belle_sip_header_to_t *to=belle_sip_header_to_parse(tmp);
391
	if (to){
392
		if (tag) belle_sip_header_to_set_tag(to,tag);
393
	}
394 395 396
	belle_sip_free(tmp);
	return to;
}
jehan's avatar
jehan committed
397 398
belle_sip_header_to_t* belle_sip_header_to_create(const belle_sip_header_address_t* address, const char *tag) {
	belle_sip_header_to_t* header= belle_sip_header_to_new();
Simon Morlat's avatar
Simon Morlat committed
399
	_belle_sip_object_copy((belle_sip_object_t*)header,(belle_sip_object_t*)address);
jehan's avatar
jehan committed
400
	belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_TO); /*restaure header name*/
jehan's avatar
fix tag  
jehan committed
401
	if (tag) belle_sip_header_to_set_tag(header,tag);
jehan's avatar
jehan committed
402 403
	return header;
}
404 405 406 407 408 409
void belle_sip_header_to_set_random_tag(belle_sip_header_to_t *obj){
	char tmp[8];
	/*not less than 32bit */
	belle_sip_header_to_set_tag(obj,belle_sip_random_token(tmp,sizeof(tmp)));
}

410 411 412 413 414 415 416 417 418 419
void belle_sip_header_to_set_tag(belle_sip_header_to_t *obj, const char *tag){
	if (tag==BELLE_SIP_RANDOM_TAG) belle_sip_header_to_set_random_tag(obj);
	else belle_sip_header_to_set_raw_tag(obj,tag);
}

const char *belle_sip_header_to_get_tag(const belle_sip_header_to_t *obj){
	return belle_sip_header_to_get_raw_tag(obj);
}


jehan's avatar
jehan committed
420
/******************************
421
 * User-Agent header inherits from header
jehan's avatar
jehan committed
422 423 424 425 426 427 428 429 430 431 432 433
 *
 ******************************/
struct _belle_sip_header_user_agent  {
	belle_sip_header_t header;
	belle_sip_list_t* products;
};

static void belle_sip_header_user_agent_destroy(belle_sip_header_user_agent_t* user_agent) {
	belle_sip_header_user_agent_set_products(user_agent,NULL);
}

static void belle_sip_header_user_agent_clone(belle_sip_header_user_agent_t* user_agent, const belle_sip_header_user_agent_t* orig){
434 435 436 437
	belle_sip_list_t* list=orig->products;
	for(;list!=NULL;list=list->next){
		belle_sip_header_user_agent_add_product(user_agent,(const char *)list->data);
	}
jehan's avatar
jehan committed
438
}
Ghislain MARY's avatar
Ghislain MARY committed
439

440
belle_sip_error_code belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agent, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
441
	belle_sip_error_code error=BELLE_SIP_OK;
jehan's avatar
jehan committed
442
	belle_sip_list_t* list = user_agent->products;
Ghislain MARY's avatar
Ghislain MARY committed
443 444
	error=belle_sip_header_marshal(BELLE_SIP_HEADER(user_agent), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
445
	for(;list!=NULL;list=list->next){
Ghislain MARY's avatar
Ghislain MARY committed
446 447
		error=belle_sip_snprintf(buff,buff_size,offset,list==user_agent->products ? "%s" : " %s",(const char *)list->data);
		if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
448
	}
Ghislain MARY's avatar
Ghislain MARY committed
449
	return error;
jehan's avatar
jehan committed
450
}
Ghislain MARY's avatar
Ghislain MARY committed
451

452
BELLE_SIP_NEW_HEADER(header_user_agent,header,"User-Agent")
jehan's avatar
jehan committed
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
BELLE_SIP_PARSE(header_user_agent)
belle_sip_list_t* belle_sip_header_user_agent_get_products(const belle_sip_header_user_agent_t* user_agent) {
	return user_agent->products;
}
void belle_sip_header_user_agent_set_products(belle_sip_header_user_agent_t* user_agent,belle_sip_list_t* products) {
	belle_sip_list_t* list;
	if (user_agent->products) {
		for (list=user_agent->products;list !=NULL; list=list->next) {
			belle_sip_free((void*)list->data);

		}
		belle_sip_list_free(user_agent->products);
	}
	user_agent->products=products;
}
void belle_sip_header_user_agent_add_product(belle_sip_header_user_agent_t* user_agent,const char* product) {
	user_agent->products = belle_sip_list_append(user_agent->products ,belle_sip_strdup(product));
}
jehan's avatar
jehan committed
471
int belle_sip_header_user_agent_get_products_as_string(const belle_sip_header_user_agent_t* user_agent,char* value,unsigned int value_size) {
Simon Morlat's avatar
Simon Morlat committed
472
	size_t result = 0;
jehan's avatar
jehan committed
473 474
	belle_sip_list_t* list = user_agent->products;
	for(;list!=NULL;list=list->next){
Ghislain MARY's avatar
Ghislain MARY committed
475
		belle_sip_snprintf(value,value_size,&result,"%s ",(const char *)list->data);
jehan's avatar
jehan committed
476 477 478 479 480
	}
	if (result>0) value[result]='\0'; /*remove last space */

	return result-1;
}
jehan's avatar
jehan committed
481

jehan's avatar
jehan committed
482
/**************************
Simon Morlat's avatar
Simon Morlat committed
483
* Via header object inherits from parameters
jehan's avatar
jehan committed
484 485 486
****************************
*/
struct _belle_sip_header_via  {
487
	belle_sip_parameters_t params_list;
Simon Morlat's avatar
Simon Morlat committed
488 489 490
	char* protocol;
	char* transport;
	char* host;
491
	int port;
jehan's avatar
jehan committed
492
	char* received;
jehan's avatar
jehan committed
493 494
};

495
static void belle_sip_header_via_destroy(belle_sip_header_via_t* via) {
Simon Morlat's avatar
Simon Morlat committed
496
	if (via->protocol) belle_sip_free(via->protocol);
497 498
	if (via->transport) belle_sip_free(via->transport);
	if (via->host) belle_sip_free(via->host);
jehan's avatar
jehan committed
499
	DESTROY_STRING(via,received)
Simon Morlat's avatar
Simon Morlat committed
500 501 502
}

static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_sip_header_via_t*orig){
503 504 505
	CLONE_STRING(belle_sip_header_via,protocol,via,orig)
	CLONE_STRING(belle_sip_header_via,transport,via,orig)
	CLONE_STRING(belle_sip_header_via,host,via,orig)
jehan's avatar
jehan committed
506
	CLONE_STRING(belle_sip_header_via,received,via,orig)
507
	via->port=orig->port;
jehan's avatar
jehan committed
508
}
509

510
belle_sip_error_code belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
511 512 513 514
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%s/%s",via->protocol,via->transport);
	if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
515 516 517

	if (via->host) {
		if (strchr(via->host,':')) { /*ipv6*/
Ghislain MARY's avatar
Ghislain MARY committed
518
			error=belle_sip_snprintf(buff,buff_size,offset," [%s]",via->host);
jehan's avatar
jehan committed
519
		} else {
Ghislain MARY's avatar
Ghislain MARY committed
520
			error=belle_sip_snprintf(buff,buff_size,offset," %s",via->host);
jehan's avatar
jehan committed
521
		}
Ghislain MARY's avatar
Ghislain MARY committed
522
		if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
523 524 525 526
	} else {
		belle_sip_warning("no host found in this via");
	}

jehan's avatar
jehan committed
527
	if (via->port > 0) {
Ghislain MARY's avatar
Ghislain MARY committed
528 529
		error=belle_sip_snprintf(buff,buff_size,offset,":%i",via->port);
		if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
530
	}
jehan's avatar
jehan committed
531
	if (via->received) {
Ghislain MARY's avatar
Ghislain MARY committed
532 533
		error=belle_sip_snprintf(buff,buff_size,offset,";received=%s",via->received);
		if (error!=BELLE_SIP_OK) return error;
jehan's avatar
jehan committed
534 535
	}

Ghislain MARY's avatar
Ghislain MARY committed
536 537 538 539
	error=belle_sip_parameters_marshal(&via->params_list, buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;

	return error;
jehan's avatar
jehan committed
540
}
jehan's avatar
jehan committed
541

542 543 544 545 546 547 548 549 550 551
belle_sip_header_via_t* belle_sip_header_via_create(const char *host, int port, const char *transport, const char *branch){
	belle_sip_header_via_t *via=belle_sip_header_via_new();
	via->host=belle_sip_strdup(host);
	via->port=port;
	via->transport=belle_sip_strdup(transport);
	via->protocol=belle_sip_strdup("SIP/2.0");
	belle_sip_header_via_set_branch(via,branch);
	return via;
}

jehan's avatar
jehan committed
552
BELLE_SIP_NEW_HEADER(header_via,parameters,BELLE_SIP_VIA)
jehan's avatar
jehan committed
553
BELLE_SIP_PARSE(header_via)
554 555 556
GET_SET_STRING(belle_sip_header_via,protocol);
GET_SET_STRING(belle_sip_header_via,transport);
GET_SET_STRING(belle_sip_header_via,host);
jehan's avatar
jehan committed
557
GET_SET_STRING(belle_sip_header_via,received);
558 559 560 561
GET_SET_INT_PRIVATE(belle_sip_header_via,port,int,_);

GET_SET_STRING_PARAM(belle_sip_header_via,branch);
GET_SET_STRING_PARAM(belle_sip_header_via,maddr);
jehan's avatar
jehan committed
562

563 564 565

GET_SET_INT_PARAM_PRIVATE(belle_sip_header_via,rport,int,_)
GET_SET_INT_PARAM_PRIVATE(belle_sip_header_via,ttl,int,_)
Simon Morlat's avatar
Simon Morlat committed
566

567
int belle_sip_header_via_set_rport (belle_sip_header_via_t* obj,int  value) {
jehan's avatar
jehan committed
568 569 570 571 572
	if (value == -1) {
		belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),"rport",NULL);
		return 0;
	}
	if (value>0 && value<65536) {
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
		_belle_sip_header_via_set_rport(obj,value);
		return 0;
	} else {
		belle_sip_error("bad rport value [%i] for via",value);
		return -1;
	}
}
int belle_sip_header_via_set_ttl (belle_sip_header_via_t* obj,int  value) {
	if (value ==-1 || (value>0 && value<=255)) {
		_belle_sip_header_via_set_ttl(obj,value);
		return 0;
	} else {
		belle_sip_error("bad ttl value [%i] for via",value);
		return -1;
	}
}
589

590 591 592 593 594 595 596 597 598
int belle_sip_header_via_set_port (belle_sip_header_via_t* obj,int  value) {
	if (value ==-1 || (value>0 && value<65536)) {
		_belle_sip_header_via_set_port(obj,value);
		return 0;
	} else {
		belle_sip_error("bad port value [%i] for via",value);
		return -1;
	}
}
Simon Morlat's avatar
Simon Morlat committed
599

600
int belle_sip_header_via_get_listening_port(const belle_sip_header_via_t *via){
Simon Morlat's avatar
Simon Morlat committed
601
	int ret=belle_sip_header_via_get_port(via);
602
	if (ret==0) ret=belle_sip_listening_point_get_well_known_port(via->transport);
Simon Morlat's avatar
Simon Morlat committed
603 604
	return ret;
}
605 606

const char* belle_sip_header_via_get_transport_lowercase(const belle_sip_header_via_t* via) {
607 608 609 610 611 612 613 614 615
	if (strcasecmp("udp",via->transport)==0) return "udp";
	else if (strcasecmp("tcp",via->transport)==0) return "tcp";
	else if (strcasecmp("tls",via->transport)==0) return "tls";
	else if (strcasecmp("dtls",via->transport)==0) return "dtls";
	else {
		belle_sip_warning("Cannot convert [%s] to lower case",via->transport);
		return via->transport;
	}
}
616
/**************************
Simon Morlat's avatar
Simon Morlat committed
617
* call_id header object inherits from object
618 619
****************************
*/
jehan's avatar
jehan committed
620
struct _belle_sip_header_call_id  {
jehan's avatar
jehan committed
621
	belle_sip_header_t header;
jehan's avatar
jehan committed
622
	const char* call_id;
623
};
jehan's avatar
jehan committed
624

jehan's avatar
jehan committed
625 626
static void belle_sip_header_call_id_destroy(belle_sip_header_call_id_t* call_id) {
	if (call_id->call_id) belle_sip_free((void*)call_id->call_id);
Simon Morlat's avatar
Simon Morlat committed
627
}
jehan's avatar
jehan committed
628

Simon Morlat's avatar
Simon Morlat committed
629
static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,const belle_sip_header_call_id_t *orig){
630
	CLONE_STRING(belle_sip_header_call_id,call_id,call_id,orig);
631
}
Ghislain MARY's avatar
Ghislain MARY committed
632

633
belle_sip_error_code belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
634 635 636 637 638
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%s",call_id->call_id);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
639
}
Ghislain MARY's avatar
Ghislain MARY committed
640

641 642 643
unsigned int belle_sip_header_call_id_equals(const belle_sip_header_call_id_t* a,const belle_sip_header_call_id_t* b) {
	return strcasecmp(a->call_id,b->call_id) == 0;
}
jehan's avatar
fix tag  
jehan committed
644
BELLE_SIP_NEW_HEADER(header_call_id,header,BELLE_SIP_CALL_ID)
jehan's avatar
jehan committed
645 646
BELLE_SIP_PARSE(header_call_id)
GET_SET_STRING(belle_sip_header_call_id,call_id);
647 648 649 650 651
/**************************
* cseq header object inherent from object
****************************
*/
struct _belle_sip_header_cseq  {
jehan's avatar
jehan committed
652
	belle_sip_header_t header;
653
	char* method;
654 655
	unsigned int seq_number;
};
jehan's avatar
jehan committed
656

657
static void belle_sip_header_cseq_destroy(belle_sip_header_cseq_t* cseq) {
658
	if (cseq->method) belle_sip_free(cseq->method);
Simon Morlat's avatar
Simon Morlat committed
659
}
660

Simon Morlat's avatar
Simon Morlat committed
661
static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const belle_sip_header_cseq_t *orig) {
662 663
	CLONE_STRING(belle_sip_header_cseq,method,cseq,orig)
	cseq->seq_number=orig->seq_number;
664
}
Ghislain MARY's avatar
Ghislain MARY committed
665

666
belle_sip_error_code belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
667 668 669 670 671
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%i %s",cseq->seq_number,cseq->method);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
672
}
Ghislain MARY's avatar
Ghislain MARY committed
673

674 675
belle_sip_header_cseq_t * belle_sip_header_cseq_create(unsigned int number, const char *method){
	belle_sip_header_cseq_t *cseq=belle_sip_header_cseq_new();
jehan's avatar
jehan committed
676
	belle_sip_header_cseq_set_method(cseq,method);
677 678 679
	cseq->seq_number=number;
	return cseq;
}
680
BELLE_SIP_NEW_HEADER(header_cseq,header,BELLE_SIP_CSEQ)
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
BELLE_SIP_PARSE(header_cseq)
GET_SET_STRING(belle_sip_header_cseq,method);
GET_SET_INT(belle_sip_header_cseq,seq_number,unsigned int)
/**************************
* content type header object inherent from parameters
****************************
*/
struct _belle_sip_header_content_type  {
	belle_sip_parameters_t params_list;
	const char* type;
	const char* subtype;
};

static void belle_sip_header_content_type_destroy(belle_sip_header_content_type_t* content_type) {
	if (content_type->type) belle_sip_free((void*)content_type->type);
	if (content_type->subtype) belle_sip_free((void*)content_type->subtype);
}
jehan's avatar
jehan committed
698

Simon Morlat's avatar
Simon Morlat committed
699
static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t* content_type, const belle_sip_header_content_type_t* orig){
700 701
	CLONE_STRING(belle_sip_header_content_type,type,content_type,orig);
	CLONE_STRING(belle_sip_header_content_type,subtype,content_type,orig);
Simon Morlat's avatar
Simon Morlat committed
702
}
Ghislain MARY's avatar
Ghislain MARY committed
703

704
belle_sip_error_code belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
705 706 707 708 709 710 711
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%s/%s",content_type->type, content_type->subtype);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_parameters_marshal(&content_type->params_list, buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
712
}
Ghislain MARY's avatar
Ghislain MARY committed
713

jehan's avatar
jehan committed
714
BELLE_SIP_NEW_HEADER(header_content_type,parameters,BELLE_SIP_CONTENT_TYPE)
715
BELLE_SIP_PARSE(header_content_type)
jehan's avatar
jehan committed
716 717 718 719 720 721
belle_sip_header_content_type_t* belle_sip_header_content_type_create (const char* type,const char* sub_type) {
	belle_sip_header_content_type_t* header = belle_sip_header_content_type_new();
	belle_sip_header_content_type_set_type(header,type);
	belle_sip_header_content_type_set_subtype(header,sub_type);
	return header;
}
722 723
GET_SET_STRING(belle_sip_header_content_type,type);
GET_SET_STRING(belle_sip_header_content_type,subtype);
jehan's avatar
jehan committed
724 725 726 727 728 729 730 731 732
/**************************
* Route header object inherent from header_address
****************************
*/
struct _belle_sip_header_route  {
	belle_sip_header_address_t address;
};

static void belle_sip_header_route_destroy(belle_sip_header_route_t* route) {
Simon Morlat's avatar
Simon Morlat committed
733 734 735
}

static void belle_sip_header_route_clone(belle_sip_header_route_t* route, const belle_sip_header_route_t* orig) {
jehan's avatar
jehan committed
736
}
Ghislain MARY's avatar
Ghislain MARY committed
737

738
belle_sip_error_code belle_sip_header_route_marshal(belle_sip_header_route_t* route, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
739 740
	BELLE_SIP_FROM_LIKE_MARSHAL(route)
}
Ghislain MARY's avatar
Ghislain MARY committed
741

jehan's avatar
jehan committed
742
BELLE_SIP_NEW_HEADER(header_route,header_address,BELLE_SIP_ROUTE)
jehan's avatar
jehan committed
743
BELLE_SIP_PARSE(header_route)
jehan's avatar
jehan committed
744 745
belle_sip_header_route_t* belle_sip_header_route_create(const belle_sip_header_address_t* route) {
	belle_sip_header_route_t* header= belle_sip_header_route_new();
jehan's avatar
jehan committed
746
	_belle_sip_object_copy((belle_sip_object_t*)header,(belle_sip_object_t*)route);
747
	belle_sip_header_set_name(BELLE_SIP_HEADER(header),BELLE_SIP_ROUTE); /*restore header name*/
jehan's avatar
jehan committed
748 749
	return header;
}
jehan's avatar
jehan committed
750 751 752 753 754 755 756 757 758
/**************************
* Record route header object inherent from header_address
****************************
*/
struct _belle_sip_header_record_route  {
	belle_sip_header_address_t address;
};

static void belle_sip_header_record_route_destroy(belle_sip_header_record_route_t* record_route) {
Simon Morlat's avatar
Simon Morlat committed
759 760 761 762
}

static void belle_sip_header_record_route_clone(belle_sip_header_record_route_t* record_route,
                                const belle_sip_header_record_route_t* orig               ) {
jehan's avatar
jehan committed
763
}
Ghislain MARY's avatar
Ghislain MARY committed
764

765
belle_sip_error_code belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
766 767
	BELLE_SIP_FROM_LIKE_MARSHAL(record_route)
}
Ghislain MARY's avatar
Ghislain MARY committed
768

jehan's avatar
jehan committed
769
BELLE_SIP_NEW_HEADER(header_record_route,header_address,BELLE_SIP_RECORD_ROUTE)
jehan's avatar
jehan committed
770
BELLE_SIP_PARSE(header_record_route)
jehan's avatar
jehan committed
771
/**************************
jehan's avatar
jehan committed
772 773 774 775 776 777 778 779 780 781 782 783 784
* Service route header object inherent from header_address
****************************
*/
struct _belle_sip_header_service_route  {
	belle_sip_header_address_t address;
};

static void belle_sip_header_service_route_destroy(belle_sip_header_service_route_t* service_route) {
}

static void belle_sip_header_service_route_clone(belle_sip_header_service_route_t* service_route,
                                const belle_sip_header_service_route_t* orig               ) {
}
Ghislain MARY's avatar
Ghislain MARY committed
785

786
belle_sip_error_code belle_sip_header_service_route_marshal(belle_sip_header_service_route_t* service_route, char* buff, size_t buff_size, size_t *offset) {
jehan's avatar
jehan committed
787 788
	BELLE_SIP_FROM_LIKE_MARSHAL(service_route)
}
Ghislain MARY's avatar
Ghislain MARY committed
789

jehan's avatar
jehan committed
790 791 792
BELLE_SIP_NEW_HEADER(header_service_route,header_address,BELLE_SIP_SERVICE_ROUTE)
BELLE_SIP_PARSE(header_service_route)
/**************************
jehan's avatar
jehan committed
793 794 795 796
* content length header object inherent from object
****************************
*/
struct _belle_sip_header_content_length  {
jehan's avatar
jehan committed
797
	belle_sip_header_t header;
jehan's avatar
jehan committed
798 799 800 801
	unsigned int content_length;
};

static void belle_sip_header_content_length_destroy(belle_sip_header_content_length_t* content_length) {
Simon Morlat's avatar
Simon Morlat committed
802
}
jehan's avatar
jehan committed
803

Simon Morlat's avatar
Simon Morlat committed
804 805
static void belle_sip_header_content_length_clone(belle_sip_header_content_length_t* content_length,
                                                 const belle_sip_header_content_length_t *orig ) {
806
	content_length->content_length=orig->content_length;
jehan's avatar
jehan committed
807
}
Simon Morlat's avatar
Simon Morlat committed
808

809
belle_sip_error_code belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff, size_t buff_size, size_t *offset) {
Ghislain MARY's avatar
Ghislain MARY committed
810 811 812 813 814
	belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff, buff_size, offset);
	if (error!=BELLE_SIP_OK) return error;
	error=belle_sip_snprintf(buff,buff_size,offset,"%i",content_length->content_length);
	if (error!=BELLE_SIP_OK) return error;
	return error;
jehan's avatar
jehan committed
815
}
Ghislain MARY's avatar
Ghislain MARY committed
816

jehan's avatar
jehan committed
817
BELLE_SIP_NEW_HEADER(header_content_length,header,BELLE_SIP_CONTENT_LENGTH)
jehan's avatar
jehan committed
818 819
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
jehan's avatar
jehan committed
820 821 822 823 824 825
belle_sip_header_content_length_t* belle_sip_header_content_length_create (int content_length)  {
	belle_sip_header_content_length_t* obj;
	obj = belle_sip_header_content_length_new();
	belle_sip_header_content_length_set_content_length(obj,content_length);
	return obj;
}
jehan's avatar
jehan committed
826 827 828 829 830 831 832 833 834 835 836 837 838 839
/**************************
* Expires header object inherent from header
****************************
*/
struct _belle_sip_header_expires  {
	belle_sip_header_t header;
	int expires;
};

static void belle_sip_header_expires_destroy(belle_sip_header_expires_t* expires) {
}

static void belle_sip_header_expires_clone(belle_sip_header_expires_t* expires,