belle_sip_headers_impl.c 35.2 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
#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
30 31 32
/************************
 * header
 ***********************/
jehan's avatar
jehan committed
33

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

jehan's avatar
jehan committed
36
void belle_sip_header_init(belle_sip_header_t *header) {
Simon Morlat's avatar
Simon Morlat committed
37

jehan's avatar
jehan committed
38
}
39
static void belle_sip_header_clone(belle_sip_header_t *header, const belle_sip_header_t *orig){
40
	CLONE_STRING(belle_sip_header,name,header,orig)
41 42 43 44
	if (belle_sip_header_get_next(orig)) {
		belle_sip_header_set_next(header,BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_get_next(orig))))) ;
	}
}
Simon Morlat's avatar
Simon Morlat committed
45
static void belle_sip_header_destroy(belle_sip_header_t *header){
jehan's avatar
jehan committed
46
	if (header->name) belle_sip_free((void*)header->name);
jehan's avatar
jehan committed
47 48 49 50 51 52 53
	if (header->next) belle_sip_object_unref(BELLE_SIP_OBJECT(header->next));
}
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next) {
	header->next = next;
}
belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* header) {
	return header->next;
jehan's avatar
jehan committed
54
}
jehan's avatar
jehan committed
55

jehan's avatar
jehan committed
56 57
int belle_sip_header_marshal(belle_sip_header_t* header, char* buff,unsigned int offset,unsigned int buff_size) {
	if (header->name) {
58
		return snprintf(buff+offset,buff_size-offset,"%s: ",header->name);
jehan's avatar
jehan committed
59 60 61 62 63
	} else {
		belle_sip_warning("no header name found");
		return 0;
	}
}
64 65 66

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_header_t);

67
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_header_t,belle_sip_object_t,belle_sip_header_destroy,belle_sip_header_clone,belle_sip_header_marshal);
Simon Morlat's avatar
Simon Morlat committed
68 69


jehan's avatar
jehan committed
70 71 72 73
/************************
 * header_address
 ***********************/
struct _belle_sip_header_address {
Simon Morlat's avatar
Simon Morlat committed
74
	belle_sip_parameters_t base;
jehan's avatar
jehan committed
75 76 77
	const char* displayname;
	belle_sip_uri_t* uri;
};
Simon Morlat's avatar
Simon Morlat committed
78

jehan's avatar
jehan committed
79 80
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
81 82
}

jehan's avatar
jehan committed
83 84 85
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
86 87
}

88
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
89 90 91 92
	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
93
}
94

jehan's avatar
jehan committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff,unsigned int offset,unsigned int buff_size) {
	/*1 display name*/
	unsigned int current_offset=offset;
	if (header->displayname) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"\"%s\" ",header->displayname);;
	}
	if (header->uri) {
		if (header->displayname || belle_sip_parameters_get_parameter_names(&header->base) !=NULL) {
			current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","<");
		}
		current_offset+=belle_sip_uri_marshal(header->uri,buff,current_offset,buff_size);
		if (header->displayname || belle_sip_parameters_get_parameter_names(&header->base) !=NULL) {
			current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",">");
		}
	}
	current_offset+=belle_sip_parameters_marshal(&header->base,buff,current_offset,buff_size);
	return current_offset-offset;
}
Simon Morlat's avatar
Simon Morlat committed
113 114

BELLE_SIP_NEW(header_address,parameters)
jehan's avatar
jehan committed
115 116
GET_SET_STRING(belle_sip_header_address,displayname);

jehan's avatar
jehan committed
117 118
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));
119
		address->displayname=_belle_sip_str_dup_and_unquote_string(value);
jehan's avatar
jehan committed
120
}
121
belle_sip_uri_t* belle_sip_header_address_get_uri(const belle_sip_header_address_t* address) {
jehan's avatar
jehan committed
122 123 124 125
	return address->uri;
}

void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri) {
126
	address->uri=(belle_sip_uri_t*)belle_sip_object_ref(uri);
jehan's avatar
jehan committed
127 128 129
}


jehan's avatar
jehan committed
130 131 132 133 134 135 136 137
/******************************
 * Extension header hinerite from header
 *
 ******************************/
struct _belle_sip_header_allow  {
	belle_sip_header_t header;
	const char* method;
};
138 139 140
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
141 142 143 144
static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) {
	if (allow->method) belle_sip_free((void*)allow->method);
}

145

jehan's avatar
jehan committed
146 147 148 149 150 151 152 153 154 155 156 157
int belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",allow->method);
	return current_offset-offset;

}
BELLE_SIP_NEW_HEADER(header_allow,header,"Allow")
BELLE_SIP_PARSE(header_allow)
GET_SET_STRING(belle_sip_header_allow,method);


jehan's avatar
jehan committed
158 159 160 161 162 163 164 165 166

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

jehan's avatar
jehan committed
167
void belle_sip_header_contact_destroy(belle_sip_header_contact_t* contact) {
Simon Morlat's avatar
Simon Morlat committed
168 169 170
}

void belle_sip_header_contact_clone(belle_sip_header_contact_t *contact, const belle_sip_header_contact_t *orig){
171
	contact->wildcard=orig->wildcard;
jehan's avatar
jehan committed
172
}
jehan's avatar
jehan committed
173 174 175 176 177 178 179 180 181 182
int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(contact), buff,offset, buff_size);
	if (contact->wildcard) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","*");
	} else {
		current_offset+=belle_sip_header_address_marshal(&contact->address, buff,current_offset, buff_size);
	}
	return current_offset-offset;
}
jehan's avatar
jehan committed
183
BELLE_SIP_NEW_HEADER(header_contact,header_address,"Contact")
jehan's avatar
jehan committed
184
BELLE_SIP_PARSE(header_contact)
jehan's avatar
jehan committed
185

jehan's avatar
jehan committed
186 187
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
188 189
GET_SET_BOOL(belle_sip_header_contact,wildcard,is);

jehan's avatar
jehan committed
190

jehan's avatar
jehan committed
191 192
int belle_sip_header_contact_set_expires(belle_sip_header_contact_t* contact, int expires) {
	if (expires < 0 ) {
193
		 belle_sip_error("bad expires value [%i] for contact",expires);
jehan's avatar
jehan committed
194 195 196 197 198 199
		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
200
	 if (qValue != -1 && qValue < 0 && qValue >1) {
201
		 belle_sip_error("bad q value [%f] for contact",qValue);
jehan's avatar
jehan committed
202 203
		 return -1;
	 }
jehan's avatar
jehan committed
204
	 _belle_sip_header_contact_set_q(contact,qValue);
jehan's avatar
jehan committed
205 206
	 return 0;
}
207
float	belle_sip_header_contact_get_qvalue(const belle_sip_header_contact_t* contact) {
jehan's avatar
jehan committed
208 209 210
	return belle_sip_header_contact_get_q(contact);
}
/**************************
jehan's avatar
jehan committed
211
* From header object inherent from header_address
jehan's avatar
jehan committed
212
****************************
jehan's avatar
jehan committed
213
*/
jehan's avatar
jehan committed
214 215 216 217 218
#define BELLE_SIP_FROM_LIKE_MARSHAL(header) \
		unsigned int current_offset=offset; \
		current_offset+=belle_sip_##header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
		current_offset+=belle_sip_header_address_marshal(&header->address, buff,current_offset, buff_size); \
		return current_offset-offset;
219

jehan's avatar
jehan committed
220 221 222 223
struct _belle_sip_header_from  {
	belle_sip_header_address_t address;
};

jehan's avatar
jehan committed
224 225 226
static void belle_sip_header_from_destroy(belle_sip_header_from_t* from) {
}

Simon Morlat's avatar
Simon Morlat committed
227 228
static void belle_sip_header_from_clone(belle_sip_header_from_t* from, const belle_sip_header_from_t* cloned) {
}
jehan's avatar
jehan committed
229 230 231
int belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff,unsigned int offset,unsigned int buff_size) {
	BELLE_SIP_FROM_LIKE_MARSHAL(from);
}
Simon Morlat's avatar
Simon Morlat committed
232

233 234 235 236 237 238 239 240
belle_sip_header_from_t* belle_sip_header_from_create(const char *address, const char *tag){
	char *tmp=belle_sip_strdup_printf("From: %s",address);
	belle_sip_header_from_t *from=belle_sip_header_from_parse(tmp);
	if (tag) belle_sip_header_from_set_tag(from,tag);
	belle_sip_free(tmp);
	return from;
}

jehan's avatar
jehan committed
241
BELLE_SIP_NEW_HEADER(header_from,header_address,"From")
jehan's avatar
jehan committed
242
BELLE_SIP_PARSE(header_from)
jehan's avatar
jehan committed
243 244 245
GET_SET_STRING_PARAM(belle_sip_header_from,tag);

/**************************
Simon Morlat's avatar
Simon Morlat committed
246
* To header object inherits from header_address
jehan's avatar
jehan committed
247 248 249 250 251
****************************
*/
struct _belle_sip_header_to  {
	belle_sip_header_address_t address;
};
jehan's avatar
jehan committed
252

jehan's avatar
jehan committed
253
static void belle_sip_header_to_destroy(belle_sip_header_to_t* to) {
Simon Morlat's avatar
Simon Morlat committed
254 255 256
}

void belle_sip_header_to_clone(belle_sip_header_to_t *contact, const belle_sip_header_to_t *orig){
jehan's avatar
jehan committed
257
}
jehan's avatar
jehan committed
258 259 260
int belle_sip_header_to_marshal(belle_sip_header_to_t* to, char* buff,unsigned int offset,unsigned int buff_size) {
	BELLE_SIP_FROM_LIKE_MARSHAL(to)
}
jehan's avatar
jehan committed
261

jehan's avatar
jehan committed
262
BELLE_SIP_NEW_HEADER(header_to,header_address,"To")
jehan's avatar
jehan committed
263 264
BELLE_SIP_PARSE(header_to)
GET_SET_STRING_PARAM(belle_sip_header_to,tag);
265

266 267 268 269 270 271 272 273
belle_sip_header_to_t* belle_sip_header_to_create(const char *address, const char *tag){
	char *tmp=belle_sip_strdup_printf("To: %s",address);
	belle_sip_header_to_t *to=belle_sip_header_to_parse(tmp);
	if (tag) belle_sip_header_to_set_tag(to,tag);
	belle_sip_free(tmp);
	return to;
}

jehan's avatar
jehan committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287
/******************************
 * User-Agent header hinerite from header
 *
 ******************************/
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){
288 289 290 291
	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
292 293 294 295 296 297 298 299 300 301 302 303 304 305
}
int belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agent, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	belle_sip_list_t* list = user_agent->products;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(user_agent), buff,current_offset, buff_size);
	for(;list!=NULL;list=list->next){
		current_offset+=snprintf(	buff+current_offset
									,buff_size-current_offset
									," %s"
									,(const char *)list->data);
	}
	return current_offset-offset;

}
306
BELLE_SIP_NEW_HEADER(header_user_agent,header,"User-Agent")
jehan's avatar
jehan committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
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
326
/**************************
Simon Morlat's avatar
Simon Morlat committed
327
* Via header object inherits from parameters
jehan's avatar
jehan committed
328 329 330
****************************
*/
struct _belle_sip_header_via  {
331
	belle_sip_parameters_t params_list;
Simon Morlat's avatar
Simon Morlat committed
332 333 334
	char* protocol;
	char* transport;
	char* host;
335
	int port;
jehan's avatar
jehan committed
336 337
};

338
static void belle_sip_header_via_destroy(belle_sip_header_via_t* via) {
Simon Morlat's avatar
Simon Morlat committed
339
	if (via->protocol) belle_sip_free(via->protocol);
340 341
	if (via->transport) belle_sip_free(via->transport);
	if (via->host) belle_sip_free(via->host);
Simon Morlat's avatar
Simon Morlat committed
342 343 344
}

static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_sip_header_via_t*orig){
345 346 347 348
	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)
	via->port=orig->port;
jehan's avatar
jehan committed
349
}
350

jehan's avatar
jehan committed
351 352 353 354 355 356 357 358 359 360 361
int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",via->protocol,via->transport);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",via->host);
	if (via->port > 0) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,":%i",via->port);
	}
	current_offset+=belle_sip_parameters_marshal(&via->params_list, buff,current_offset, buff_size);
	return current_offset-offset;
}
jehan's avatar
jehan committed
362

363 364 365 366 367 368 369 370 371 372
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;
}

373
BELLE_SIP_NEW_HEADER(header_via,parameters,"Via")
jehan's avatar
jehan committed
374
BELLE_SIP_PARSE(header_via)
375 376 377 378 379 380 381 382 383 384 385
GET_SET_STRING(belle_sip_header_via,protocol);
GET_SET_STRING(belle_sip_header_via,transport);
GET_SET_STRING(belle_sip_header_via,host);
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);
GET_SET_STRING_PARAM(belle_sip_header_via,received);

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
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
int belle_sip_header_via_set_rport (belle_sip_header_via_t* obj,int  value) {
	if (value ==-1 || (value>0 && value<65536)) {
		_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;
	}
}
405

406 407 408 409 410 411 412 413 414
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
415

416
int belle_sip_header_via_get_listening_port(const belle_sip_header_via_t *via){
Simon Morlat's avatar
Simon Morlat committed
417 418 419 420 421
	int ret=belle_sip_header_via_get_port(via);
	if (ret==-1) ret=belle_sip_listening_point_get_well_known_port(via->protocol);
	return ret;
}

422
/**************************
Simon Morlat's avatar
Simon Morlat committed
423
* call_id header object inherits from object
424 425
****************************
*/
jehan's avatar
jehan committed
426
struct _belle_sip_header_call_id  {
jehan's avatar
jehan committed
427
	belle_sip_header_t header;
jehan's avatar
jehan committed
428
	const char* call_id;
429
};
jehan's avatar
jehan committed
430

jehan's avatar
jehan committed
431 432
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
433
}
jehan's avatar
jehan committed
434

Simon Morlat's avatar
Simon Morlat committed
435
static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,const belle_sip_header_call_id_t *orig){
436
	CLONE_STRING(belle_sip_header_call_id,call_id,call_id,orig);
437
}
jehan's avatar
jehan committed
438 439 440 441 442 443
int belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",call_id->call_id);
	return current_offset-offset;
}
444

jehan's avatar
jehan committed
445
BELLE_SIP_NEW_HEADER(header_call_id,header,"Call-ID")
jehan's avatar
jehan committed
446 447
BELLE_SIP_PARSE(header_call_id)
GET_SET_STRING(belle_sip_header_call_id,call_id);
448 449 450 451 452
/**************************
* cseq header object inherent from object
****************************
*/
struct _belle_sip_header_cseq  {
jehan's avatar
jehan committed
453
	belle_sip_header_t header;
454
	char* method;
455 456
	unsigned int seq_number;
};
jehan's avatar
jehan committed
457

458
static void belle_sip_header_cseq_destroy(belle_sip_header_cseq_t* cseq) {
459
	if (cseq->method) belle_sip_free(cseq->method);
Simon Morlat's avatar
Simon Morlat committed
460
}
461

Simon Morlat's avatar
Simon Morlat committed
462
static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const belle_sip_header_cseq_t *orig) {
463 464
	CLONE_STRING(belle_sip_header_cseq,method,cseq,orig)
	cseq->seq_number=orig->seq_number;
465
}
jehan's avatar
jehan committed
466 467 468 469 470 471
int belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i %s",cseq->seq_number,cseq->method);
	return current_offset-offset;
}
472 473 474 475 476 477
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();
	cseq->method=belle_sip_strdup(method);
	cseq->seq_number=number;
	return cseq;
}
jehan's avatar
jehan committed
478
BELLE_SIP_NEW_HEADER(header_cseq,header,"CSeq")
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
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
496

Simon Morlat's avatar
Simon Morlat committed
497
static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t* content_type, const belle_sip_header_content_type_t* orig){
498 499
	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
500
}
jehan's avatar
jehan committed
501 502 503 504 505 506 507
int belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",content_type->type, content_type->subtype);
	current_offset+=belle_sip_parameters_marshal(&content_type->params_list, buff,current_offset, buff_size);
	return current_offset-offset;
}
jehan's avatar
jehan committed
508
BELLE_SIP_NEW_HEADER(header_content_type,parameters,"Content-Type")
509 510 511
BELLE_SIP_PARSE(header_content_type)
GET_SET_STRING(belle_sip_header_content_type,type);
GET_SET_STRING(belle_sip_header_content_type,subtype);
jehan's avatar
jehan committed
512 513 514 515 516 517 518 519 520
/**************************
* 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
521 522 523
}

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
524
}
jehan's avatar
jehan committed
525 526 527
int belle_sip_header_route_marshal(belle_sip_header_route_t* route, char* buff,unsigned int offset,unsigned int buff_size) {
	BELLE_SIP_FROM_LIKE_MARSHAL(route)
}
jehan's avatar
jehan committed
528
BELLE_SIP_NEW_HEADER(header_route,header_address,"Route")
jehan's avatar
jehan committed
529 530 531 532 533 534 535 536 537 538
BELLE_SIP_PARSE(header_route)
/**************************
* 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
539 540 541 542
}

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
543
}
jehan's avatar
jehan committed
544 545 546
int belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff,unsigned int offset,unsigned int buff_size) {
	BELLE_SIP_FROM_LIKE_MARSHAL(record_route)
}
jehan's avatar
jehan committed
547
BELLE_SIP_NEW_HEADER(header_record_route,header_address,"Record-Route")
jehan's avatar
jehan committed
548
BELLE_SIP_PARSE(header_record_route)
jehan's avatar
jehan committed
549 550 551 552 553
/**************************
* content length header object inherent from object
****************************
*/
struct _belle_sip_header_content_length  {
jehan's avatar
jehan committed
554
	belle_sip_header_t header;
jehan's avatar
jehan committed
555 556 557 558
	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
559
}
jehan's avatar
jehan committed
560

Simon Morlat's avatar
Simon Morlat committed
561 562
static void belle_sip_header_content_length_clone(belle_sip_header_content_length_t* content_length,
                                                 const belle_sip_header_content_length_t *orig ) {
563
	content_length->content_length=orig->content_length;
jehan's avatar
jehan committed
564
}
Simon Morlat's avatar
Simon Morlat committed
565

jehan's avatar
jehan committed
566 567 568 569 570 571
int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
	return current_offset-offset;
}
jehan's avatar
jehan committed
572
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
jehan's avatar
jehan committed
573 574
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
jehan's avatar
jehan committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588
/**************************
* 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,
                                                 const belle_sip_header_expires_t *orig ) {
589
	expires->expires=orig->expires;
jehan's avatar
jehan committed
590 591 592 593 594 595 596 597 598 599 600 601
}

int belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(expires), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",expires->expires);
	return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_expires,header,"Expires")
BELLE_SIP_PARSE(header_expires)
GET_SET_INT(belle_sip_header_expires,expires,int)

jehan's avatar
jehan committed
602 603 604 605 606 607 608 609 610 611 612 613 614 615
/******************************
 * Extension header hinerite from header
 *
 ******************************/
struct _belle_sip_header_extension  {
	belle_sip_header_t header;
	const char* value;
};

static void belle_sip_header_extension_destroy(belle_sip_header_extension_t* extension) {
	if (extension->value) belle_sip_free((void*)extension->value);
}

static void belle_sip_header_extension_clone(belle_sip_header_extension_t* extension, const belle_sip_header_extension_t* orig){
616
	CLONE_STRING(belle_sip_header_extension,value,extension,orig)
jehan's avatar
jehan committed
617
}
jehan's avatar
jehan committed
618 619 620 621 622
int belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(extension), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",extension->value);
	return current_offset-offset;
jehan's avatar
jehan committed
623

jehan's avatar
jehan committed
624
}
jehan's avatar
jehan committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
BELLE_SIP_NEW_HEADER(header_extension,header,NULL)

/**
 * special case for this header. I don't know why
 */
belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* value) {
	pANTLR3_INPUT_STREAM           input;
	pbelle_sip_messageLexer               lex;
	pANTLR3_COMMON_TOKEN_STREAM    tokens;
	pbelle_sip_messageParser              parser;
	input  = antlr3NewAsciiStringCopyStream	(
			(pANTLR3_UINT8)value,
			(ANTLR3_UINT32)strlen(value),
			((void *)0));
	lex    = belle_sip_messageLexerNew                (input);
	tokens = antlr3CommonTokenStreamSourceNew  (1025, lex->pLexer->rec->state->tokSource);
	parser = belle_sip_messageParserNew               (tokens);
	belle_sip_messageParser_header_extension_return l_parsed_object = parser->header_extension(parser,FALSE);
	parser ->free(parser);
	tokens ->free(tokens);
	lex    ->free(lex);
	input  ->close(input);
	if (l_parsed_object.ret == NULL) belle_sip_error("Parser error for [%s]",value);\
	return BELLE_SIP_HEADER_EXTENSION(l_parsed_object.ret);
}
GET_SET_STRING(belle_sip_header_extension,value);
651
/**************************
652
*Authorization header object inherent from parameters
653 654
****************************
*/
jehan's avatar
jehan committed
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
#define AUTH_BASE \
	belle_sip_parameters_t params_list; \
	const char* scheme; \
	const char* realm; \
	const char* nonce; \
	const char* algorithm; \
	const char* opaque; \
	const char* qop; \

#define AUTH_BASE_DESTROY(obj) \
	if (obj->scheme) belle_sip_free((void*)obj->scheme);\
	if (obj->realm) belle_sip_free((void*)obj->realm);\
	if (obj->nonce) belle_sip_free((void*)obj->nonce);\
	if (obj->algorithm) belle_sip_free((void*)obj->algorithm);\
	if (obj->opaque) belle_sip_free((void*)obj->opaque);\
	if (obj->qop) belle_sip_free((void*)obj->qop);\
jehan's avatar
jehan committed
671 672
	/*if (obj->params_list) FIXME free list*/

673 674 675 676 677 678 679
#define AUTH_BASE_CLONE(object_type,dest,src) \
		CLONE_STRING(object_type,scheme,dest,src)\
		CLONE_STRING(object_type,realm,dest,src)\
		CLONE_STRING(object_type,nonce,dest,src)\
		CLONE_STRING(object_type,algorithm,dest,src)\
		CLONE_STRING(object_type,opaque,dest,src)\
		CLONE_STRING(object_type,qop,dest,src)
jehan's avatar
jehan committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

#define AUTH_BASE_MARSHAL(header) \
	unsigned int current_offset=offset;\
	char* border=" ";\
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
	const belle_sip_list_t* list=belle_sip_parameters_get_parameters(&header->params_list);\
	if (header->scheme) { \
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",header->scheme);\
		} else { \
			belle_sip_error("missing mandatory scheme"); \
		} \
	for(;list!=NULL;list=list->next){\
		belle_sip_param_pair_t* container = list->data;\
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s%s=%s",border, container->name,container->value);\
		border=", ";\
	}\
	if (header->realm) {\
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%srealm=\"%s\"",border,header->realm);\
		border=", ";\
		}\
	if (header->nonce) {\
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snonce=\"%s\"",border,header->nonce);\
		border=", ";\
		}\
	if (header->algorithm) {\
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,header->algorithm);\
		border=", ";\
		}\
	if (header->opaque) {\
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sopaque=\"%s\"",border,header->opaque);\
		border=", ";\
		}



jehan's avatar
jehan committed
715

jehan's avatar
jehan committed
716
	struct _belle_sip_header_authorization  {
jehan's avatar
jehan committed
717
	AUTH_BASE
718
	const char* username;
jehan's avatar
jehan committed
719
	belle_sip_uri_t* uri;
jehan's avatar
jehan committed
720
	const char* response;
721 722
	const char* cnonce;
	int nonce_count;
723 724 725 726 727 728

};


static void belle_sip_header_authorization_destroy(belle_sip_header_authorization_t* authorization) {
	if (authorization->username) belle_sip_free((void*)authorization->username);
jehan's avatar
jehan committed
729 730 731
	if (authorization->uri) {
			belle_sip_object_unref(BELLE_SIP_OBJECT(authorization->uri));
	}
732
	if (authorization->cnonce) belle_sip_free((void*)authorization->cnonce);
jehan's avatar
jehan committed
733
	AUTH_BASE_DESTROY(authorization)
734 735 736 737
}

static void belle_sip_header_authorization_clone(belle_sip_header_authorization_t* authorization,
                                                 const belle_sip_header_authorization_t *orig ) {
738 739 740 741 742 743 744 745
	AUTH_BASE_CLONE(belle_sip_header_authorization,authorization,orig)
	CLONE_STRING(belle_sip_header_authorization,username,authorization,orig)
	if (belle_sip_header_authorization_get_uri(orig)) {
		belle_sip_header_authorization_set_uri(authorization,BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_authorization_get_uri(orig)))));
	}
	CLONE_STRING(belle_sip_header_authorization,response,authorization,orig)
	CLONE_STRING(belle_sip_header_authorization,cnonce,authorization,orig)
	authorization->nonce_count=orig->nonce_count;
746
}
747 748
static void belle_sip_header_authorization_init(belle_sip_header_authorization_t* authorization) {
}
749

jehan's avatar
jehan committed
750 751 752
belle_sip_uri_t* belle_sip_header_authorization_get_uri(const belle_sip_header_authorization_t* authorization) {
	return authorization->uri;
}
753

jehan's avatar
jehan committed
754 755 756 757 758 759 760
void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* authorization, belle_sip_uri_t* uri) {
	if (authorization->uri) {
		belle_sip_object_unref(BELLE_SIP_OBJECT(authorization->uri));
	}
	authorization->uri=uri;
	if (authorization->uri) belle_sip_object_ref(authorization->uri);
}
jehan's avatar
jehan committed
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
int belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* authorization, char* buff,unsigned int offset,unsigned int buff_size) {
	AUTH_BASE_MARSHAL(authorization)
	if (authorization->username) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%susername=\"%s\"",border,authorization->username);\
		border=", ";
		}
	if (authorization->uri) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s uri=\"",border);
		border=", ";
		current_offset+=belle_sip_uri_marshal(authorization->uri,buff,current_offset,buff_size);
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\"");
		}
	if (authorization->algorithm) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,authorization->algorithm);
		border=", ";
		}
	if (authorization->response) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sresponse=\"%s\"",border,authorization->response);
		border=", ";
		}
	if (authorization->cnonce) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%scnonce=\"%s\"",border,authorization->cnonce);
		border=", ";
		}
	if (authorization->nonce_count>0) {
jehan's avatar
jehan committed
786 787 788 789 790 791
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snc=%08i",border,authorization->nonce_count);
		border=", ";
	}
	if (authorization->qop) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,authorization->qop);
	}
jehan's avatar
jehan committed
792 793
	return current_offset-offset;
}
794
BELLE_SIP_NEW_HEADER(header_authorization,parameters,"Authorization")
795
BELLE_SIP_PARSE(header_authorization)
jehan's avatar
jehan committed
796
GET_SET_STRING(belle_sip_header_authorization,scheme);
797
GET_SET_STRING(belle_sip_header_authorization,username);
jehan's avatar
jehan committed
798 799
GET_SET_STRING(belle_sip_header_authorization,realm);
GET_SET_STRING(belle_sip_header_authorization,nonce);
jehan's avatar
jehan committed
800
GET_SET_STRING(belle_sip_header_authorization,response);
jehan's avatar
jehan committed
801
GET_SET_STRING(belle_sip_header_authorization,algorithm);
802 803
GET_SET_STRING(belle_sip_header_authorization,cnonce);
GET_SET_STRING(belle_sip_header_authorization,opaque);
jehan's avatar
jehan committed
804
GET_SET_STRING(belle_sip_header_authorization,qop);
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
GET_SET_INT(belle_sip_header_authorization,nonce_count,int)

/**************************
*Proxy-Authorization header object inherent from parameters
****************************
*/
struct _belle_sip_header_proxy_authorization  {
	belle_sip_header_authorization_t authorization;
};


static void belle_sip_header_proxy_authorization_destroy(belle_sip_header_proxy_authorization_t* proxy_authorization) {
}

static void belle_sip_header_proxy_authorization_clone(belle_sip_header_proxy_authorization_t* proxy_authorization,
                                                 const belle_sip_header_proxy_authorization_t *orig ) {
}
jehan's avatar
jehan committed
822 823 824
int belle_sip_header_proxy_authorization_marshal(belle_sip_header_proxy_authorization_t* proxy_authorization, char* buff,unsigned int offset,unsigned int buff_size) {
	return belle_sip_header_authorization_marshal(&proxy_authorization->authorization,buff,offset,buff_size);
}
825 826
BELLE_SIP_NEW_HEADER(header_proxy_authorization,header_authorization,"Proxy-Authorization")
BELLE_SIP_PARSE(header_proxy_authorization)
jehan's avatar
jehan committed
827 828 829 830 831 832 833 834 835 836 837 838
/**************************
*WWW-Authorization header object inherent from parameters
****************************
*/
struct _belle_sip_header_www_authenticate  {
	AUTH_BASE
	const char* domain;
	unsigned int stale;
};


static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authenticate_t* www_authenticate) {
jehan's avatar
jehan committed
839 840 841 842
	if (www_authenticate->domain) belle_sip_free((void*)www_authenticate->domain);
}
void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
	www_authenticate->stale=-1;
jehan's avatar
jehan committed
843 844 845
}
static void belle_sip_header_www_authenticate_clone(belle_sip_header_www_authenticate_t* www_authenticate,
                                                 const belle_sip_header_www_authenticate_t *orig ) {
846 847 848
	AUTH_BASE_CLONE(belle_sip_header_www_authenticate,www_authenticate,orig)
	CLONE_STRING(belle_sip_header_www_authenticate,domain,www_authenticate,orig)
	www_authenticate->stale=orig->stale;
jehan's avatar
jehan committed
849
}
jehan's avatar
jehan committed
850 851 852 853 854 855 856
int belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_t* www_authenticate, char* buff,unsigned int offset,unsigned int buff_size) {
	AUTH_BASE_MARSHAL(www_authenticate)
	if (www_authenticate->domain) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sdomain=\"%s\"",border,www_authenticate->domain);\
		border=", ";
		}
	if (www_authenticate->stale>=0) {
jehan's avatar
jehan committed
857
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sstale=%s",border,www_authenticate->stale?"true":"false");
jehan's avatar
jehan committed
858
		}
jehan's avatar
jehan committed
859 860 861 862
	if (www_authenticate->qop) {
		current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=\"%s\"",border,www_authenticate->qop);
		border=", ";
	}
jehan's avatar
jehan committed
863 864 865
	return current_offset-offset;
}
BELLE_SIP_NEW_HEADER_INIT(header_www_authenticate,parameters,"WWW-Authenticate",header_www_authenticate)
jehan's avatar
jehan committed
866 867 868 869 870 871 872 873 874
BELLE_SIP_PARSE(header_www_authenticate)
GET_SET_STRING(belle_sip_header_www_authenticate,scheme);
GET_SET_STRING(belle_sip_header_www_authenticate,realm);
GET_SET_STRING(belle_sip_header_www_authenticate,nonce);
GET_SET_STRING(belle_sip_header_www_authenticate,algorithm);
GET_SET_STRING(belle_sip_header_www_authenticate,opaque);
GET_SET_STRING(belle_sip_header_www_authenticate,qop);
GET_SET_STRING(belle_sip_header_www_authenticate,domain)
GET_SET_BOOL(belle_sip_header_www_authenticate,stale,is)
jehan's avatar
jehan committed
875 876 877 878 879 880 881 882 883 884 885 886 887 888
/**************************
* max forwards header object inherent from header
****************************
*/
struct _belle_sip_header_max_forwards  {
	belle_sip_header_t header;
	int max_forwards;
};

static void belle_sip_header_max_forwards_destroy(belle_sip_header_max_forwards_t* max_forwards) {
}

static void belle_sip_header_max_forwards_clone(belle_sip_header_max_forwards_t* max_forwards,
                                                 const belle_sip_header_max_forwards_t *orig ) {
889
	max_forwards->max_forwards=orig->max_forwards;
jehan's avatar
jehan committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903
}

int belle_sip_header_max_forwards_marshal(belle_sip_header_max_forwards_t* max_forwards, char* buff,unsigned int offset,unsigned int buff_size) {
	unsigned int current_offset=offset;
	current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(max_forwards), buff,current_offset, buff_size);
	current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",max_forwards->max_forwards);
	return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_max_forwards,header,"Max-Forwards")
BELLE_SIP_PARSE(header_max_forwards)
GET_SET_INT(belle_sip_header_max_forwards,max_forwards,int)
int belle_sip_header_max_forwards_decrement_max_forwards(belle_sip_header_max_forwards_t* max_forwards) {
	return max_forwards->max_forwards--;
}