belle_sip_internal.h 33.4 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
/*
	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/>.
*/
jehan's avatar
jehan committed
18 19
#ifndef belle_utils_h
#define belle_utils_h
20 21 22 23

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Simon Morlat's avatar
Simon Morlat committed
24
#include <sys/types.h>
25
#include <errno.h>
Simon Morlat's avatar
Simon Morlat committed
26

Simon Morlat's avatar
Simon Morlat committed
27
/* include all public headers*/
Simon Morlat's avatar
Simon Morlat committed
28
#include "belle-sip/belle-sip.h"
jehan's avatar
jehan committed
29

Simon Morlat's avatar
Simon Morlat committed
30 31
#include "port.h"

32 33
#ifdef HAVE_CONFIG_H

jehan's avatar
jehan committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#ifdef PACKAGE
#undef PACKAGE
#endif
#ifdef PACKAGE_BUGREPORT
#undef PACKAGE_BUGREPORT
#endif
#ifdef PACKAGE_NAME
#undef PACKAGE_NAME
#endif
#ifdef PACKAGE_STRING
#undef PACKAGE_STRING
#endif
#ifdef PACKAGE_TARNAME
#undef PACKAGE_TARNAME
#endif
#ifdef VERSION
#undef VERSION
#endif
52 53 54
#ifdef PACKAGE_VERSION
#undef PACKAGE_VERSION
#endif
jehan's avatar
jehan committed
55 56

#include "config.h"
57

58 59 60
#else

#ifndef PACKAGE_VERSION
61
#error "PACKAGE_VERSION must be defined and equal to the VERSION file included in the belle-sip repository"
62 63
#endif

jehan's avatar
jehan committed
64 65
#endif

66 67
#include "port.h"

68 69 70 71
/*etc*/

#define BELLE_SIP_INTERFACE_GET_METHODS(obj,interface) \
	((BELLE_SIP_INTERFACE_METHODS_TYPE(interface)*)belle_sip_object_get_interface_methods((belle_sip_object_t*)obj,BELLE_SIP_INTERFACE_ID(interface)))
Simon Morlat's avatar
Simon Morlat committed
72

Simon Morlat's avatar
Simon Morlat committed
73
#define __BELLE_SIP_INVOKE_LISTENER_BEGIN(list,interface_name,method) \
74
	if (list!=NULL) {\
Simon Morlat's avatar
Simon Morlat committed
75 76
		belle_sip_list_t *__copy=belle_sip_list_copy_with_data((list), (void* (*)(void*))belle_sip_object_ref);\
		const belle_sip_list_t *__elem=__copy;\
77
		do{\
78
			void *__method;\
79
			interface_name *__obj=(interface_name*)__elem->data;\
80
			__method=BELLE_SIP_INTERFACE_GET_METHODS(__obj,interface_name)->method;\
Simon Morlat's avatar
Simon Morlat committed
81
			if (__method) BELLE_SIP_INTERFACE_GET_METHODS(__obj,interface_name)->
82 83 84 85

#define __BELLE_SIP_INVOKE_LISTENER_END \
			__elem=__elem->next;\
		}while(__elem!=NULL);\
Simon Morlat's avatar
Simon Morlat committed
86
		belle_sip_list_free_with_data(__copy,belle_sip_object_unref);\
87 88 89
	}

#define BELLE_SIP_INVOKE_LISTENERS_VOID(list,interface_name,method) \
Simon Morlat's avatar
Simon Morlat committed
90
			__BELLE_SIP_INVOKE_LISTENER_BEGIN(list,interface_name,method)\
91 92 93 94
			method(__obj);\
			__BELLE_SIP_INVOKE_LISTENER_END

#define BELLE_SIP_INVOKE_LISTENERS_ARG(list,interface_name,method,arg) \
Simon Morlat's avatar
Simon Morlat committed
95
	__BELLE_SIP_INVOKE_LISTENER_BEGIN(list,interface_name,method)\
96 97 98 99 100
	method(__obj,arg);\
	__BELLE_SIP_INVOKE_LISTENER_END


#define BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(list,interface_name,method,arg1,arg2) \
Simon Morlat's avatar
Simon Morlat committed
101
			__BELLE_SIP_INVOKE_LISTENER_BEGIN(list,interface_name,method)\
102 103 104 105 106 107 108 109 110 111 112 113 114 115
			method(__obj,arg1,arg2);\
			__BELLE_SIP_INVOKE_LISTENER_END

#define BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2_ARG3(list,interface_name,method,arg1,arg2,arg3) \
			__BELLE_SIP_INVOKE_LISTENER_BEGIN(list,interface_name)\
			method(__obj,arg1,arg2,arg3);\
			__BELLE_SIP_INVOKE_LISTENER_END

typedef struct weak_ref{
	struct weak_ref *next;
	belle_sip_object_destroy_notify_t notify;
	void *userpointer;
}weak_ref_t;

Simon Morlat's avatar
Simon Morlat committed
116

117
void *belle_sip_object_get_interface_methods(belle_sip_object_t *obj, belle_sip_interface_id_t ifid);
Simon Morlat's avatar
Simon Morlat committed
118 119
/*used internally by unref()*/
void belle_sip_object_delete(void *obj);
120 121
void belle_sip_object_pool_add(belle_sip_object_pool_t *pool, belle_sip_object_t *obj);
void belle_sip_object_pool_remove(belle_sip_object_pool_t *pool, belle_sip_object_t *obj);
Simon Morlat's avatar
Simon Morlat committed
122

123

124
#define BELLE_SIP_OBJECT_VPTR(obj,object_type) ((BELLE_SIP_OBJECT_VPTR_TYPE(object_type)*)(((belle_sip_object_t*)obj)->vptr))
Simon Morlat's avatar
Simon Morlat committed
125 126 127 128 129
#define belle_sip_object_init(obj)		/*nothing*/


/*list of all vptrs (classes) used in belle-sip*/
BELLE_SIP_DECLARE_VPTR(belle_sip_object_t);
130 131 132 133 134 135 136 137 138 139 140 141
BELLE_SIP_DECLARE_VPTR(belle_sip_stack_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_datagram_listening_point_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_provider_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_main_loop_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_source_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_resolver_context_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dialog_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_address_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_contact_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_from_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_to_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_via_t);
Simon Morlat's avatar
Simon Morlat committed
142
BELLE_SIP_DECLARE_VPTR(belle_sip_uri_t);
143 144 145
BELLE_SIP_DECLARE_VPTR(belle_sip_message_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_request_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_response_t);
Simon Morlat's avatar
Simon Morlat committed
146
BELLE_SIP_DECLARE_VPTR(belle_sip_parameters_t);
147 148 149 150 151 152 153 154 155 156 157
BELLE_SIP_DECLARE_VPTR(belle_sip_header_call_id_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_cseq_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_content_type_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_route_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_record_route_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_user_agent_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_content_length_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_extension_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_authorization_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_www_authenticate_t);
jehan's avatar
jehan committed
158
BELLE_SIP_DECLARE_VPTR(belle_sip_header_proxy_authenticate_t);
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
BELLE_SIP_DECLARE_VPTR(belle_sip_header_proxy_authorization_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_max_forwards_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_expires_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_allow_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_attribute_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_bandwidth_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_connection_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_email_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_info_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_key_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_media_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_media_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_origin_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_phone_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_repeate_time_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_session_name_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_time_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_time_description_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_uri_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_version_t);
BELLE_SIP_DECLARE_VPTR(belle_sdp_base_description_t);
181
BELLE_SIP_DECLARE_VPTR(belle_sdp_mime_parameter_t);
jehan's avatar
jehan committed
182
BELLE_SIP_DECLARE_VPTR(belle_sip_refresher_t);
jehan's avatar
jehan committed
183
BELLE_SIP_DECLARE_VPTR(belle_sip_header_subscription_state_t);
jehan's avatar
jehan committed
184
BELLE_SIP_DECLARE_VPTR(belle_sip_header_service_route_t);
jehan's avatar
jehan committed
185
BELLE_SIP_DECLARE_VPTR(belle_sip_header_refer_to_t);
jehan's avatar
jehan committed
186 187
BELLE_SIP_DECLARE_VPTR(belle_sip_header_referred_by_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_header_replaces_t);
Simon Morlat's avatar
Simon Morlat committed
188
BELLE_SIP_DECLARE_VPTR(belle_sip_header_date_t);
Simon Morlat's avatar
Simon Morlat committed
189
BELLE_SIP_DECLARE_VPTR(belle_sip_hop_t);
190
BELLE_SIP_DECLARE_VPTR(belle_sip_object_pool_t);
jehan's avatar
jehan committed
191
BELLE_SIP_DECLARE_VPTR(belle_sip_header_p_preferred_identity_t);
jehan's avatar
jehan committed
192
BELLE_SIP_DECLARE_VPTR(belle_sip_header_privacy_t);
jehan's avatar
jehan committed
193

Simon Morlat's avatar
Simon Morlat committed
194
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
jehan's avatar
jehan committed
195

jehan's avatar
jehan committed
196 197 198



Simon Morlat's avatar
Simon Morlat committed
199
struct belle_sip_source{
200
	belle_sip_object_t base;
Simon Morlat's avatar
Simon Morlat committed
201 202
	belle_sip_list_t node;
	unsigned long id;
203
	belle_sip_fd_t fd;
204
	unsigned short events,revents;
Simon Morlat's avatar
Simon Morlat committed
205 206 207 208 209 210
	int timeout;
	void *data;
	uint64_t expire_ms;
	int index; /* index in pollfd table */
	belle_sip_source_func_t notify;
	belle_sip_source_remove_callback_t on_remove;
Simon Morlat's avatar
Simon Morlat committed
211 212
	unsigned char cancelled;
	unsigned char expired;
Simon Morlat's avatar
Simon Morlat committed
213
	unsigned char oneshot;
214
	unsigned char notify_required; /*for testing purpose, use to ask for being scheduled*/
215
	belle_sip_socket_t sock;
Simon Morlat's avatar
Simon Morlat committed
216
};
jehan's avatar
jehan committed
217

218
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t fd, unsigned int events, unsigned int timeout_value_ms);
219
void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_fd_t fd, unsigned int events, unsigned int timeout_value_ms);
Simon Morlat's avatar
Simon Morlat committed
220 221
void belle_sip_source_uninit(belle_sip_source_t *s);

jehan's avatar
jehan committed
222 223
#define belle_list_next(elem) ((elem)->next)

224
/* include private headers */
225
#include "channel.h"
jehan's avatar
jehan committed
226

227

228

229 230 231 232

#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
	
233
belle_sip_list_t *belle_sip_list_new(void *data);
234
belle_sip_list_t*  belle_sip_list_append_link(belle_sip_list_t* elem,belle_sip_list_t *new_elem);
Simon Morlat's avatar
Simon Morlat committed
235
belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip_compare_func compare_func, const void *user_data);
236

jehan's avatar
jehan committed
237 238 239 240 241 242 243 244 245 246 247 248
#define belle_sip_list_next(elem) ((elem)->next)





#undef MIN
#define MIN(a,b)	((a)>(b) ? (b) : (a))
#undef MAX
#define MAX(a,b)	((a)>(b) ? (a) : (b))


Ghislain MARY's avatar
Ghislain MARY committed
249
BELLESIP_INTERNAL_EXPORT char * belle_sip_concat (const char *str, ...);
jehan's avatar
jehan committed
250

Ghislain MARY's avatar
Ghislain MARY committed
251
BELLESIP_INTERNAL_EXPORT uint64_t belle_sip_time_ms(void);
252

Ghislain MARY's avatar
Ghislain MARY committed
253
BELLESIP_INTERNAL_EXPORT unsigned int belle_sip_random(void);
254 255


jehan's avatar
jehan committed
256 257
/*parameters accessors*/
#define GET_SET_STRING(object_type,attribute) \
258
	const char* object_type##_get_##attribute (const object_type##_t* obj) {\
jehan's avatar
jehan committed
259 260 261
		return obj->attribute;\
	}\
	void object_type##_set_##attribute (object_type##_t* obj,const char* value) {\
Simon Morlat's avatar
Simon Morlat committed
262
		if (obj->attribute != NULL) belle_sip_free((void*)obj->attribute);\
263
		if (value) {\
Simon Morlat's avatar
Simon Morlat committed
264
			obj->attribute=belle_sip_strdup(value); \
265
		} else obj->attribute=NULL;\
jehan's avatar
jehan committed
266
	}
jehan's avatar
jehan committed
267 268 269 270 271 272
/*#define GET_SET_STRING_PARAM_NULL_ALLOWED(object_type,attribute) \
	GET_STRING_PARAM2(object_type,attribute,attribute) \
	void object_type##_set_##func_name (object_type##_t* obj,const char* value) {\
		belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),#attribute,value);\
	}
*/
jehan's avatar
jehan committed
273 274
#define GET_SET_STRING_PARAM(object_type,attribute) GET_SET_STRING_PARAM2(object_type,attribute,attribute)
#define GET_SET_STRING_PARAM2(object_type,attribute,func_name) \
jehan's avatar
jehan committed
275 276
	GET_STRING_PARAM2(object_type,attribute,func_name) \
	void object_type##_set_##func_name (object_type##_t* obj,const char* value) {\
277
	if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(obj),#attribute) && !value) {\
jehan's avatar
jehan committed
278 279 280 281 282 283
		belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(obj),#attribute); \
	} else \
		belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),#attribute,value);\
	}

#define GET_STRING_PARAM2(object_type,attribute,func_name) \
284
	const char* object_type##_get_##func_name (const object_type##_t* obj) {\
jehan's avatar
jehan committed
285 286
	const char* l_value = belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
	if (l_value == NULL) { \
Simon Morlat's avatar
Simon Morlat committed
287
		/*belle_sip_warning("cannot find parameters [%s]",#attribute);*/\
jehan's avatar
jehan committed
288 289 290 291 292
		return NULL;\
	}\
	return l_value;\
	}

jehan's avatar
jehan committed
293 294
#define DESTROY_STRING(object,attribute) if (object->attribute) belle_sip_free((void*)object->attribute);

jehan's avatar
jehan committed
295 296 297
#define CLONE_STRING_GENERIC(object_type_src,object_type_dest,attribute,dest,src) \
		if ( object_type_src##_get_##attribute (src)) {\
			object_type_dest##_set_##attribute(dest,object_type_src##_get_##attribute(src));\
298
		}
jehan's avatar
jehan committed
299

jehan's avatar
jehan committed
300 301
#define CLONE_STRING(object_type,attribute,dest,src) CLONE_STRING_GENERIC(object_type,object_type,attribute,dest,src)

jehan's avatar
jehan committed
302 303 304
#define GET_SET_INT(object_type,attribute,type) GET_SET_INT_PRIVATE(object_type,attribute,type,)

#define GET_SET_INT_PRIVATE(object_type,attribute,type,set_prefix) \
305
	type  object_type##_get_##attribute (const object_type##_t* obj) {\
jehan's avatar
jehan committed
306 307 308 309 310
		return obj->attribute;\
	}\
	void set_prefix##object_type##_set_##attribute (object_type##_t* obj,type  value) {\
		obj->attribute=value;\
	}
jehan's avatar
jehan committed
311 312 313 314 315
#define GET_SET_INT_PARAM(object_type,attribute,type) GET_SET_INT_PARAM_PRIVATE(object_type,attribute,type,)
#define GET_SET_INT_PARAM2(object_type,attribute,type,func_name) GET_SET_INT_PARAM_PRIVATE2(object_type,attribute,type,,func_name)

#define ATO_(type,value) ATO_##type(value)
#define ATO_int(value) atoi(value)
316
#define ATO_float(value) (float)strtod(value,NULL)
jehan's avatar
jehan committed
317 318 319 320 321 322
#define FORMAT_(type) FORMAT_##type
#define FORMAT_int    "%i"
#define FORMAT_float  "%f"

#define GET_SET_INT_PARAM_PRIVATE(object_type,attribute,type,set_prefix) GET_SET_INT_PARAM_PRIVATE2(object_type,attribute,type,set_prefix,attribute)
#define GET_SET_INT_PARAM_PRIVATE2(object_type,attribute,type,set_prefix,func_name) \
323
	type  object_type##_get_##func_name (const object_type##_t* obj) {\
jehan's avatar
jehan committed
324 325
		const char* l_value = belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
		if (l_value == NULL) { \
jehan's avatar
jehan committed
326
			/*belle_sip_error("cannot find parameters [%s]",#attribute);*/\
jehan's avatar
jehan committed
327 328 329 330 331 332
			return -1;\
		}\
		return ATO_(type,l_value);\
	}\
	void set_prefix##object_type##_set_##func_name (object_type##_t* obj,type  value) {\
		char l_str_value[16];\
333 334 335 336
		if (value == -1) { \
			belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
			return;\
		}\
jehan's avatar
jehan committed
337 338 339
		snprintf(l_str_value,16,FORMAT_(type),value);\
		belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),#attribute,(const char*)l_str_value);\
	}
jehan's avatar
jehan committed
340 341

#define GET_SET_BOOL(object_type,attribute,getter) \
342
	unsigned int object_type##_##getter##_##attribute (const object_type##_t* obj) {\
jehan's avatar
jehan committed
343 344 345 346 347
		return obj->attribute;\
	}\
	void object_type##_set_##attribute (object_type##_t* obj,unsigned int value) {\
		obj->attribute=value;\
	}
jehan's avatar
jehan committed
348
#define GET_SET_BOOL_PARAM2(object_type,attribute,getter,func_name) \
349
	unsigned int object_type##_##getter##_##func_name (const object_type##_t* obj) {\
350
		return belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
jehan's avatar
jehan committed
351 352 353 354
	}\
	void object_type##_set_##func_name (object_type##_t* obj,unsigned int value) {\
		belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(obj),#attribute,NULL);\
	}
jehan's avatar
jehan committed
355

356 357 358 359 360 361 362 363 364
#if HAVE_ANTLR_STRING_STREAM_NEW
#define ANTLR_STREAM_NEW(object_type, value,length) \
antlr3StringStreamNew((pANTLR3_UINT8)value,ANTLR3_ENC_8BIT,(ANTLR3_UINT32)length,(pANTLR3_UINT8)#object_type)
#else
#define ANTLR_STREAM_NEW(object_type, value, length) \
antlr3NewAsciiStringCopyStream((pANTLR3_UINT8)value,(ANTLR3_UINT32)length,NULL)
#endif /*HAVE_ANTLR_STRING_STREAM_NEW*/


jehan's avatar
jehan committed
365 366 367 368 369 370
#define BELLE_SIP_PARSE(object_type) \
belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value) { \
	pANTLR3_INPUT_STREAM           input; \
	pbelle_sip_messageLexer               lex; \
	pANTLR3_COMMON_TOKEN_STREAM    tokens; \
	pbelle_sip_messageParser              parser; \
371
	belle_sip_##object_type##_t* l_parsed_object; \
372
	input  = ANTLR_STREAM_NEW(object_type,value,strlen(value));\
jehan's avatar
jehan committed
373 374 375
	lex    = belle_sip_messageLexerNew                (input);\
	tokens = antlr3CommonTokenStreamSourceNew  (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
	parser = belle_sip_messageParserNew               (tokens);\
376
	l_parsed_object = parser->object_type(parser);\
jehan's avatar
jehan committed
377 378 379 380
	parser ->free(parser);\
	tokens ->free(tokens);\
	lex    ->free(lex);\
	input  ->close(input);\
jehan's avatar
jehan committed
381
	if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
jehan's avatar
jehan committed
382 383 384
	return l_parsed_object;\
}

385 386 387
#define BELLE_SIP_NEW(object_type,super_type) \
	BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_##object_type##_t); \
	BELLE_SIP_INSTANCIATE_VPTR(	belle_sip_##object_type##_t\
jehan's avatar
jehan committed
388 389 390
									, belle_sip_##super_type##_t\
									, belle_sip_##object_type##_destroy\
									, belle_sip_##object_type##_clone\
391
									, belle_sip_##object_type##_marshal, TRUE); \
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
	belle_sip_##object_type##_t* belle_sip_##object_type##_new () { \
		belle_sip_##object_type##_t* l_object = belle_sip_object_new(belle_sip_##object_type##_t);\
		belle_sip_##super_type##_init((belle_sip_##super_type##_t*)l_object); \
		belle_sip_##object_type##_init((belle_sip_##object_type##_t*) l_object); \
		return l_object;\
	}

	
#define BELLE_SIP_NEW_HEADER(object_type,super_type,name) BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,header)
#define BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,init_type) \
	BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_##object_type##_t); \
	BELLE_SIP_INSTANCIATE_VPTR(	belle_sip_##object_type##_t\
								, belle_sip_##super_type##_t\
								, belle_sip_##object_type##_destroy\
								, belle_sip_##object_type##_clone\
								, belle_sip_##object_type##_marshal, TRUE); \
	belle_sip_##object_type##_t* belle_sip_##object_type##_new () { \
Simon Morlat's avatar
Simon Morlat committed
409
		belle_sip_##object_type##_t* l_object = belle_sip_object_new(belle_sip_##object_type##_t);\
410
		belle_sip_##super_type##_init((belle_sip_##super_type##_t*)l_object); \
jehan's avatar
jehan committed
411
		belle_sip_##init_type##_init((belle_sip_##init_type##_t*) l_object); \
jehan's avatar
jehan committed
412
		if (name) belle_sip_header_set_name(BELLE_SIP_HEADER(l_object),name);\
413 414
		return l_object;\
	}
jehan's avatar
jehan committed
415 416 417 418 419 420 421 422 423
typedef struct belle_sip_param_pair_t {
	int ref;
	char* name;
	char* value;
} belle_sip_param_pair_t;


belle_sip_param_pair_t* belle_sip_param_pair_new(const char* name,const char* value);

jehan's avatar
jehan committed
424
void belle_sip_param_pair_destroy(belle_sip_param_pair_t*  pair) ;
jehan's avatar
jehan committed
425 426

int belle_sip_param_pair_comp_func(const belle_sip_param_pair_t *a, const char*b) ;
jehan's avatar
jehan committed
427
int belle_sip_param_pair_case_comp_func(const belle_sip_param_pair_t *a, const char*b) ;
jehan's avatar
jehan committed
428 429 430 431 432 433

belle_sip_param_pair_t* belle_sip_param_pair_ref(belle_sip_param_pair_t* obj);

void belle_sip_param_pair_unref(belle_sip_param_pair_t* obj);


jehan's avatar
jehan committed
434
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value);
jehan's avatar
jehan committed
435

jehan's avatar
jehan committed
436 437 438
/*calss header*/
struct _belle_sip_header {
	belle_sip_object_t base;
jehan's avatar
jehan committed
439
	belle_sip_header_t* next;
Simon Morlat's avatar
Simon Morlat committed
440 441
	char *name;
	char *unparsed_value;
jehan's avatar
jehan committed
442
};
Simon Morlat's avatar
Simon Morlat committed
443

jehan's avatar
jehan committed
444
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next);
445
BELLESIP_INTERNAL_EXPORT belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* headers);
Simon Morlat's avatar
Simon Morlat committed
446
void belle_sip_response_fill_for_dialog(belle_sip_response_t *obj, belle_sip_request_t *req);
447
void belle_sip_util_copy_headers(belle_sip_message_t *orig, belle_sip_message_t *dest, const char*header, int multiple);
jehan's avatar
jehan committed
448

jehan's avatar
jehan committed
449
void belle_sip_header_init(belle_sip_header_t* obj);
jehan's avatar
jehan committed
450 451
/*class parameters*/
struct _belle_sip_parameters {
jehan's avatar
jehan committed
452
	belle_sip_header_t base;
jehan's avatar
jehan committed
453 454 455 456 457 458
	belle_sip_list_t* param_list;
	belle_sip_list_t* paramnames_list;
};

void belle_sip_parameters_init(belle_sip_parameters_t *obj);

Simon Morlat's avatar
Simon Morlat committed
459
/*
460
 * Listening points
Simon Morlat's avatar
Simon Morlat committed
461 462
*/

Simon Morlat's avatar
Simon Morlat committed
463
#include "listeningpoint_internal.h"
464

Simon Morlat's avatar
Simon Morlat committed
465 466 467

struct belle_sip_hop{
	belle_sip_object_t base;
468
	char *cname;
Simon Morlat's avatar
Simon Morlat committed
469 470 471 472 473 474
	char *host;
	char *transport;
	int port;
};


475 476 477 478 479 480
/*
 belle_sip_stack_t
*/
struct belle_sip_stack{
	belle_sip_object_t base;
	belle_sip_main_loop_t *ml;
481
	belle_sip_timer_config_t timer_config;
482
	int transport_timeout;
483
	int inactive_transport_timeout;
484
	int dns_timeout;
Simon Morlat's avatar
Simon Morlat committed
485
	int tx_delay; /*used to simulate network transmission delay, for tests*/
486
	int send_error; /* used to simulate network error. if <0, channel_send will return this value*/
487 488
	int resolver_tx_delay; /*used to simulate network transmission delay, for tests*/
	int resolver_send_error;	/* used to simulate network error*/
Simon Morlat's avatar
Simon Morlat committed
489
	int dscp;
jehan's avatar
jehan committed
490
	char *dns_user_hosts_file; /* used to load additional hosts file for tests */
491 492
};

493
belle_sip_hop_t* belle_sip_hop_new(const char* transport, const char *cname, const char* host,int port);
Simon Morlat's avatar
Simon Morlat committed
494
belle_sip_hop_t* belle_sip_hop_new_from_uri(const belle_sip_uri_t *uri);
495

Simon Morlat's avatar
Simon Morlat committed
496
belle_sip_hop_t * belle_sip_stack_get_next_hop(belle_sip_stack_t *stack, belle_sip_request_t *req);
497
const belle_sip_timer_config_t *belle_sip_stack_get_timer_config(const belle_sip_stack_t *stack);
498 499 500 501

/*
 belle_sip_provider_t
*/
502 503 504 505 506 507

struct belle_sip_provider{
	belle_sip_object_t base;
	belle_sip_stack_t *stack;
	belle_sip_list_t *lps; /*listening points*/
	belle_sip_list_t *listeners;
jehan's avatar
jehan committed
508
	belle_sip_list_t *internal_listeners; /*for transaction internaly managed by belle-sip. I.E by refreshers*/
Simon Morlat's avatar
Simon Morlat committed
509
	belle_sip_list_t *client_transactions;
Simon Morlat's avatar
Simon Morlat committed
510
	belle_sip_list_t *server_transactions;
Simon Morlat's avatar
Simon Morlat committed
511
	belle_sip_list_t *dialogs;
512
	belle_sip_list_t *auth_contexts;
513 514
	unsigned char rport_enabled; /*0 if rport should not be set in via header*/
	unsigned char nat_helper;
515 516
};

517
belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
Simon Morlat's avatar
Simon Morlat committed
518 519 520
void belle_sip_provider_add_client_transaction(belle_sip_provider_t *prov, belle_sip_client_transaction_t *t);
belle_sip_client_transaction_t *belle_sip_provider_find_matching_client_transaction(belle_sip_provider_t *prov, belle_sip_response_t *resp);
void belle_sip_provider_remove_client_transaction(belle_sip_provider_t *prov, belle_sip_client_transaction_t *t);
Simon Morlat's avatar
Simon Morlat committed
521 522 523 524
void belle_sip_provider_add_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
belle_sip_server_transaction_t * belle_sip_provider_find_matching_server_transaction(belle_sip_provider_t *prov, 
                                                                                   belle_sip_request_t *req);
void belle_sip_provider_remove_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
525
void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, belle_sip_transaction_t *t);
526
belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, const belle_sip_hop_t *hop);
Simon Morlat's avatar
Simon Morlat committed
527 528
void belle_sip_provider_add_dialog(belle_sip_provider_t *prov, belle_sip_dialog_t *dialog);
void belle_sip_provider_remove_dialog(belle_sip_provider_t *prov, belle_sip_dialog_t *dialog);
529
void belle_sip_provider_release_channel(belle_sip_provider_t *p, belle_sip_channel_t *chan);
530
void belle_sip_provider_add_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, int prepend);
531
void belle_sip_provider_remove_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l);
532
belle_sip_client_transaction_t * belle_sip_provider_find_matching_client_transaction_from_req(belle_sip_provider_t *prov, belle_sip_request_t *req) ;
533 534
/*for testing purpose only:*/
void belle_sip_provider_dispatch_message(belle_sip_provider_t *prov, belle_sip_message_t *msg);
535

536 537 538 539 540
typedef struct listener_ctx{
	belle_sip_listener_t *listener;
	void *data;
}listener_ctx_t;

jehan's avatar
jehan committed
541
#define BELLE_SIP_PROVIDER_INVOKE_LISTENERS_FOR_TRANSACTION(t,callback,event) \
Simon Morlat's avatar
Simon Morlat committed
542
		BELLE_SIP_PROVIDER_INVOKE_LISTENERS((t)->is_internal?(t)->provider->internal_listeners:(t)->provider->listeners,callback,event)
jehan's avatar
jehan committed
543 544 545

#define BELLE_SIP_PROVIDER_INVOKE_LISTENERS(listeners,callback,event) \
	BELLE_SIP_INVOKE_LISTENERS_ARG((listeners),belle_sip_listener_t,callback,(event))
546

547

548 549 550 551 552 553 554 555 556 557 558 559
struct _belle_sip_message {
	belle_sip_object_t base;
	belle_sip_list_t* header_list;
	char* body;
	unsigned int body_length;
};
	
struct _belle_sip_request {
	belle_sip_message_t message;
	char* method;
	belle_sip_uri_t* uri;
	belle_sip_dialog_t *dialog;/*set if request was created by a dialog to avoid to search in dialog list*/
560
	char *rfc2543_branch; /*computed 'branch' id in case we receive this request from an old RFC2543 stack*/
561 562 563
	unsigned char dialog_queued;
};
	
564 565 566 567
/*
 belle_sip_transaction_t
*/

568 569 570 571
struct belle_sip_transaction{
	belle_sip_object_t base;
	belle_sip_provider_t *provider; /*the provider that created this transaction */
	belle_sip_request_t *request;
572
	belle_sip_response_t *last_response;
Simon Morlat's avatar
Simon Morlat committed
573
	belle_sip_channel_t *channel;
Simon Morlat's avatar
Simon Morlat committed
574
	belle_sip_dialog_t *dialog;
575 576 577
	char *branch_id;
	belle_sip_transaction_state_t state;
	void *appdata;
578 579
	unsigned char is_internal;
	unsigned char timed_out; 
580 581
};

Simon Morlat's avatar
Simon Morlat committed
582 583 584 585 586

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_transaction_t,belle_sip_object_t)
	void (*on_terminate)(belle_sip_transaction_t *obj);
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

587
static BELLESIP_INLINE const belle_sip_timer_config_t * belle_sip_transaction_get_timer_config(belle_sip_transaction_t *obj){
Simon Morlat's avatar
Simon Morlat committed
588 589 590
	return belle_sip_stack_get_timer_config(obj->provider->stack);
}

591
static BELLESIP_INLINE void belle_sip_transaction_start_timer(belle_sip_transaction_t *obj, belle_sip_source_t *timer){
Simon Morlat's avatar
Simon Morlat committed
592 593
	belle_sip_main_loop_add_source(obj->provider->stack->ml,timer);
}
594
/** */
595
static BELLESIP_INLINE void belle_sip_transaction_stop_timer(belle_sip_transaction_t *obj, belle_sip_source_t *timer){
Simon Morlat's avatar
Simon Morlat committed
596 597 598 599
	belle_sip_main_loop_remove_source(obj->provider->stack->ml,timer);
}

void belle_sip_transaction_notify_timeout(belle_sip_transaction_t *t);
Simon Morlat's avatar
Simon Morlat committed
600

Simon Morlat's avatar
Simon Morlat committed
601 602
void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog);

jehan's avatar
jehan committed
603 604
void belle_sip_transaction_set_state(belle_sip_transaction_t *t, belle_sip_transaction_state_t state);

Simon Morlat's avatar
Simon Morlat committed
605 606 607 608 609 610 611 612 613 614
/*
 *
 *
 *	Client transaction
 *
 *
*/

struct belle_sip_client_transaction{
	belle_sip_transaction_t base;
615
	belle_sip_uri_t* preset_route; /*use to store outbound proxy, will be helpful for refresher*/
616
	belle_sip_hop_t* next_hop; /*use to send cancel request*/
Simon Morlat's avatar
Simon Morlat committed
617 618 619 620
};

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_client_transaction_t,belle_sip_transaction_t)
	void (*send_request)(belle_sip_client_transaction_t *);
621
	void (*on_response)(belle_sip_client_transaction_t *obj, belle_sip_response_t *resp);
Simon Morlat's avatar
Simon Morlat committed
622
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
623

Simon Morlat's avatar
Simon Morlat committed
624
void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, belle_sip_provider_t *prov, belle_sip_request_t *req);
625 626
void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t, belle_sip_response_t *resp);
void belle_sip_client_transaction_notify_response(belle_sip_client_transaction_t *t, belle_sip_response_t *resp);
627

Simon Morlat's avatar
Simon Morlat committed
628 629
struct belle_sip_ict{
	belle_sip_client_transaction_t base;
630 631 632
	belle_sip_source_t *timer_A;
	belle_sip_source_t *timer_B;
	belle_sip_source_t *timer_D;
633
	belle_sip_source_t *timer_M;
634
	belle_sip_request_t *ack;
Simon Morlat's avatar
Simon Morlat committed
635 636 637 638 639 640 641 642 643 644 645
};

typedef struct belle_sip_ict belle_sip_ict_t;

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_ict_t,belle_sip_client_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

belle_sip_ict_t * belle_sip_ict_new(belle_sip_provider_t *prov, belle_sip_request_t *req);

struct belle_sip_nict{
	belle_sip_client_transaction_t base;
Simon Morlat's avatar
Simon Morlat committed
646 647 648
	belle_sip_source_t *timer_F;
	belle_sip_source_t *timer_E;
	belle_sip_source_t *timer_K;
Simon Morlat's avatar
Simon Morlat committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
};

typedef struct belle_sip_nict belle_sip_nict_t;

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_nict_t,belle_sip_client_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

belle_sip_nict_t * belle_sip_nict_new(belle_sip_provider_t *prov, belle_sip_request_t *req);


/*
 *
 *
 *	Server transaction
 *
 *
*/

struct belle_sip_server_transaction{
	belle_sip_transaction_t base;
669
	char to_tag[8];
Simon Morlat's avatar
Simon Morlat committed
670 671 672
};

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_server_transaction_t,belle_sip_transaction_t)
673 674
	int (*send_new_response)(belle_sip_server_transaction_t *, belle_sip_response_t *resp);
	void (*on_request_retransmission)(belle_sip_server_transaction_t *obj);
Simon Morlat's avatar
Simon Morlat committed
675 676
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

677
void belle_sip_server_transaction_init(belle_sip_server_transaction_t *t, belle_sip_provider_t *prov,belle_sip_request_t *req);
Simon Morlat's avatar
Simon Morlat committed
678
void belle_sip_server_transaction_on_request(belle_sip_server_transaction_t *t, belle_sip_request_t *req);
679

Simon Morlat's avatar
Simon Morlat committed
680 681
struct belle_sip_ist{
	belle_sip_server_transaction_t base;
682 683 684
	belle_sip_source_t *timer_G;
	belle_sip_source_t *timer_H;
	belle_sip_source_t *timer_I;
685
	belle_sip_source_t *timer_L;
Simon Morlat's avatar
Simon Morlat committed
686 687 688 689 690 691 692 693
};

typedef struct belle_sip_ist belle_sip_ist_t;

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_ist_t,belle_sip_server_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

belle_sip_ist_t * belle_sip_ist_new(belle_sip_provider_t *prov, belle_sip_request_t *req);
694 695
/* returns 0 if the ack should be notified to TU, or -1 otherwise*/
int belle_sip_ist_process_ack(belle_sip_ist_t *obj, belle_sip_message_t *ack);
Simon Morlat's avatar
Simon Morlat committed
696 697 698

struct belle_sip_nist{
	belle_sip_server_transaction_t base;
699
	belle_sip_source_t *timer_J;
Simon Morlat's avatar
Simon Morlat committed
700 701 702 703 704 705 706 707 708
};

typedef struct belle_sip_nist belle_sip_nist_t;

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_nist_t,belle_sip_server_transaction_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

belle_sip_nist_t * belle_sip_nist_new(belle_sip_provider_t *prov, belle_sip_request_t *req);

Simon Morlat's avatar
Simon Morlat committed
709 710 711 712 713 714

/*
 * Dialogs
 */ 
struct belle_sip_dialog{
	belle_sip_object_t base;
715
	void *appdata;
Simon Morlat's avatar
Simon Morlat committed
716 717
	belle_sip_provider_t *provider;
	belle_sip_request_t *last_out_invite;
718 719 720 721
	belle_sip_request_t *last_out_ack; /*so that it can be retransmitted when needed*/
	belle_sip_response_t *last_200Ok;
	belle_sip_source_t *timer_200Ok;
	belle_sip_source_t *timer_200Ok_end;
Simon Morlat's avatar
Simon Morlat committed
722
	belle_sip_dialog_state_t state;
jehan's avatar
jehan committed
723
	belle_sip_dialog_state_t previous_state;
Simon Morlat's avatar
Simon Morlat committed
724 725 726 727 728 729 730 731 732
	belle_sip_header_call_id_t *call_id;
	belle_sip_header_address_t *local_party;
	belle_sip_header_address_t *remote_party;
	belle_sip_list_t *route_set;
	belle_sip_header_address_t *remote_target;
	char *local_tag;
	char *remote_tag;
	unsigned int local_cseq;
	unsigned int remote_cseq;
jehan's avatar
jehan committed
733
	belle_sip_transaction_t* last_transaction;
jehan's avatar
jehan committed
734
	belle_sip_header_privacy_t* privacy;
735 736 737 738 739
	belle_sip_list_t *queued_ct;/* queued client transactions*/
	unsigned char is_server;
	unsigned char is_secure;
	unsigned char terminate_on_bye;
	unsigned char needs_ack;
Simon Morlat's avatar
Simon Morlat committed
740 741 742
};

belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t);
jehan's avatar
jehan committed
743
belle_sip_dialog_t * belle_sip_provider_create_dialog_internal(belle_sip_provider_t *prov, belle_sip_transaction_t *t,unsigned int check_last_resp);
744
int belle_sip_dialog_is_authorized_transaction(const belle_sip_dialog_t *dialog,const char* method) ;
Simon Morlat's avatar
Simon Morlat committed
745 746 747
/*returns 1 if message belongs to the dialog, 0 otherwise */
int _belle_sip_dialog_match(belle_sip_dialog_t *obj, const char *call_id, const char *local_tag, const char *remote_tag);
int belle_sip_dialog_match(belle_sip_dialog_t *obj, belle_sip_message_t *msg, int as_uas);
jehan's avatar
jehan committed
748
int belle_sip_dialog_update(belle_sip_dialog_t *obj,belle_sip_transaction_t* transaction, int as_uas);
Simon Morlat's avatar
Simon Morlat committed
749
void belle_sip_dialog_check_ack_sent(belle_sip_dialog_t*obj);
750
int belle_sip_dialog_handle_ack(belle_sip_dialog_t *obj, belle_sip_request_t *ack);
751
void belle_sip_dialog_queue_client_transaction(belle_sip_dialog_t *dialog, belle_sip_client_transaction_t *tr);
jehan's avatar
jehan committed
752

Simon Morlat's avatar
Simon Morlat committed
753 754 755
/*
 belle_sip_response_t
*/
jehan's avatar
jehan committed
756
belle_sip_hop_t* belle_sip_response_get_return_hop(belle_sip_response_t *msg);
Simon Morlat's avatar
Simon Morlat committed
757

jehan's avatar
jehan committed
758 759
#define IS_TOKEN(token) \
		(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
jehan's avatar
jehan committed
760
		strcasecmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
761
char* _belle_sip_str_dup_and_unquote_string(const char* quoted_string);
762

jehan's avatar
jehan committed
763 764 765 766 767
#define IS_HEADER_NAMED(name,compressed_name) (IS_TOKEN(compressed_name) || IS_TOKEN(name))

#define STRCASECMP_HEADER_NAMED(name,compressed_name,value) \
		(strcasecmp(compressed_name,(const char*)value) == 0 || strcasecmp(name,(const char*)value) == 0 )

jehan's avatar
jehan committed
768 769 770 771 772 773 774 775 776
/*********************************************************
 * SDP
 */
#define BELLE_SDP_PARSE(object_type) \
belle_sdp_##object_type##_t* belle_sdp_##object_type##_parse (const char* value) { \
	pANTLR3_INPUT_STREAM           input; \
	pbelle_sdpLexer               lex; \
	pANTLR3_COMMON_TOKEN_STREAM    tokens; \
	pbelle_sdpParser              parser; \
777
	belle_sdp_##object_type##_t* l_parsed_object; \
778
	input  = ANTLR_STREAM_NEW(object_type, value,strlen(value));\
jehan's avatar
jehan committed
779 780 781
	lex    = belle_sdpLexerNew                (input);\
	tokens = antlr3CommonTokenStreamSourceNew  (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
	parser = belle_sdpParserNew               (tokens);\
782
	l_parsed_object = parser->object_type(parser).ret;\
jehan's avatar
jehan committed
783 784 785 786 787 788 789 790
	parser ->free(parser);\
	tokens ->free(tokens);\
	lex    ->free(lex);\
	input  ->close(input);\
	if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
	return l_parsed_object;\
}
#define BELLE_SDP_NEW(object_type,super_type) \
791
		BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_##object_type##_t); \
jehan's avatar
jehan committed
792 793 794 795
		BELLE_SIP_INSTANCIATE_VPTR(	belle_sdp_##object_type##_t\
									, super_type##_t\
									, belle_sdp_##object_type##_destroy\
									, belle_sdp_##object_type##_clone\
Simon Morlat's avatar
Simon Morlat committed
796
									, belle_sdp_##object_type##_marshal, TRUE); \
jehan's avatar
jehan committed
797 798 799 800 801
		belle_sdp_##object_type##_t* belle_sdp_##object_type##_new () { \
		belle_sdp_##object_type##_t* l_object = belle_sip_object_new(belle_sdp_##object_type##_t);\
		super_type##_init((super_type##_t*)l_object); \
		return l_object;\
	}
jehan's avatar
jehan committed
802
#define BELLE_SDP_NEW_WITH_CTR(object_type,super_type) \
803
		BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_##object_type##_t); \
jehan's avatar
jehan committed
804 805 806 807
		BELLE_SIP_INSTANCIATE_VPTR(	belle_sdp_##object_type##_t\
									, super_type##_t\
									, belle_sdp_##object_type##_destroy\
									, belle_sdp_##object_type##_clone\
Simon Morlat's avatar
Simon Morlat committed
808
									, belle_sdp_##object_type##_marshal,TRUE); \
jehan's avatar
jehan committed
809 810 811 812 813 814
		belle_sdp_##object_type##_t* belle_sdp_##object_type##_new () { \
		belle_sdp_##object_type##_t* l_object = belle_sip_object_new(belle_sdp_##object_type##_t);\
		super_type##_init((super_type##_t*)l_object); \
		belle_sdp_##object_type##_init(l_object); \
		return l_object;\
	}
jehan's avatar
jehan committed
815 816 817



jehan's avatar
jehan committed
818 819 820 821 822 823
struct belle_sip_dialog_terminated_event{
	belle_sip_provider_t *source;
	belle_sip_dialog_t *dialog;
};

struct belle_sip_io_error_event{
824
	belle_sip_object_t *source;  /*the object impacted by this error*/
jehan's avatar
jehan committed
825 826
	const char *transport;
	const char *host;
827
	unsigned int port;
jehan's avatar
jehan committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
};

struct belle_sip_request_event{
	belle_sip_provider_t *source;
	belle_sip_server_transaction_t *server_transaction;
	belle_sip_dialog_t *dialog;
	belle_sip_request_t *request;
};

struct belle_sip_response_event{
	belle_sip_provider_t *source;
	belle_sip_client_transaction_t *client_transaction;
	belle_sip_dialog_t *dialog;
	belle_sip_response_t *response;
};

struct belle_sip_timeout_event{
	belle_sip_provider_t *source;
	belle_sip_transaction_t *transaction;
	int is_server_transaction;
};

struct belle_sip_transaction_terminated_event{
	belle_sip_provider_t *source;
	belle_sip_transaction_t *transaction;
	int is_server_transaction;
};

856 857 858 859 860 861 862 863
struct belle_sip_auth_event {
	char* username;
	char* userid;
	char* realm;
	char* passwd;
	char* ha1;
};
belle_sip_auth_event_t* belle_sip_auth_event_create(const char* realm,const char* username);
jehan's avatar
jehan committed
864

jehan's avatar
jehan committed
865 866 867 868
/*
 * refresher
 * */
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction);
869

jehan's avatar
jehan committed
870

jehan's avatar
jehan committed
871 872 873
/*
 * returns a char, even if entry is escaped*/
int belle_sip_get_char (const char*a,int n,char*out);
874
/*return an escaped string*/
875 876
BELLESIP_INTERNAL_EXPORT	char* belle_sip_to_escaped_string(const char* buff) ;
BELLESIP_INTERNAL_EXPORT	char* belle_sip_to_unescaped_string(const char* buff) ;
jehan's avatar
jehan committed
877

878 879

#define BELLE_SIP_SOCKET_TIMEOUT 30000
Simon Morlat's avatar
Simon Morlat committed
880

Simon Morlat's avatar
Simon Morlat committed
881 882 883
#define BELLE_SIP_BRANCH_ID_LENGTH 10
/*Shall not be less than 32bit */
#define BELLE_SIP_TAG_LENGTH 6
884
#define BELLE_SIP_MAX_TO_STRING_SIZE 2048
885

886
void belle_sip_header_contact_set_unknown(belle_sip_header_contact_t *a, int value);
887
void belle_sip_request_set_dialog(belle_sip_request_t *req, belle_sip_dialog_t *dialog);
888
void belle_sip_request_set_rfc2543_branch(belle_sip_request_t *req, const char *rfc2543branch);
889
void belle_sip_dialog_update_request(belle_sip_dialog_t *dialog, belle_sip_request_t *req);
890

jehan's avatar
jehan committed
891
#endif