belle_sip_internal.h 33.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
/*
	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

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;\
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) \
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) \
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) \
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;

116

117
void *belle_sip_object_get_interface_methods(belle_sip_object_t *obj, belle_sip_interface_id_t ifid);
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);
122

123

124
#define BELLE_SIP_OBJECT_VPTR(obj,object_type) ((BELLE_SIP_OBJECT_VPTR_TYPE(object_type)*)(((belle_sip_object_t*)obj)->vptr))
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);
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);
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 194
BELLE_SIP_DECLARE_VPTR(belle_sip_certificates_chain_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_signing_key_t);
jehan's avatar
jehan committed
195

Simon Morlat's avatar
Simon Morlat committed
196
typedef void (*belle_sip_source_remove_callback_t)(belle_sip_source_t *);
jehan's avatar
jehan committed
197

jehan's avatar
jehan committed
198 199 200



Simon Morlat's avatar
Simon Morlat committed
201
struct belle_sip_source{
202
	belle_sip_object_t base;
Simon Morlat's avatar
Simon Morlat committed
203 204
	belle_sip_list_t node;
	unsigned long id;
205
	belle_sip_fd_t fd;
206
	unsigned short events,revents;
Simon Morlat's avatar
Simon Morlat committed
207 208 209 210 211 212
	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
213 214
	unsigned char cancelled;
	unsigned char expired;
Simon Morlat's avatar
Simon Morlat committed
215
	unsigned char oneshot;
216
	unsigned char notify_required; /*for testing purpose, use to ask for being scheduled*/
217
	belle_sip_socket_t sock;
Simon Morlat's avatar
Simon Morlat committed
218
};
jehan's avatar
jehan committed
219

220
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);
221
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);
222 223
void belle_sip_source_uninit(belle_sip_source_t *s);

jehan's avatar
jehan committed
224 225
#define belle_list_next(elem) ((elem)->next)

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

229

230

231 232 233 234

#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
	
235
belle_sip_list_t *belle_sip_list_new(void *data);
236
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
237
belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip_compare_func compare_func, const void *user_data);
238

jehan's avatar
jehan committed
239 240 241 242 243 244 245 246 247 248 249 250
#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
251
BELLESIP_INTERNAL_EXPORT char * belle_sip_concat (const char *str, ...);
jehan's avatar
jehan committed
252

253
BELLESIP_INTERNAL_EXPORT uint64_t belle_sip_time_ms(void);
254

Ghislain MARY's avatar
Ghislain MARY committed
255
BELLESIP_INTERNAL_EXPORT unsigned int belle_sip_random(void);
256 257


jehan's avatar
jehan committed
258 259
/*parameters accessors*/
#define GET_SET_STRING(object_type,attribute) \
260
	const char* object_type##_get_##attribute (const object_type##_t* obj) {\
jehan's avatar
jehan committed
261 262 263
		return obj->attribute;\
	}\
	void object_type##_set_##attribute (object_type##_t* obj,const char* value) {\
Simon Morlat's avatar
Simon Morlat committed
264
		if (obj->attribute != NULL) belle_sip_free((void*)obj->attribute);\
265
		if (value) {\
Simon Morlat's avatar
Simon Morlat committed
266
			obj->attribute=belle_sip_strdup(value); \
267
		} else obj->attribute=NULL;\
jehan's avatar
jehan committed
268
	}
jehan's avatar
jehan committed
269 270 271 272 273 274
/*#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);\
	}
*/
275 276
#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
277 278
	GET_STRING_PARAM2(object_type,attribute,func_name) \
	void object_type##_set_##func_name (object_type##_t* obj,const char* value) {\
279
	if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(obj),#attribute) && !value) {\
jehan's avatar
jehan committed
280 281 282 283 284 285
		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) \
286
	const char* object_type##_get_##func_name (const object_type##_t* obj) {\
287 288
	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
289
		/*belle_sip_warning("cannot find parameters [%s]",#attribute);*/\
290 291 292 293 294
		return NULL;\
	}\
	return l_value;\
	}

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

jehan's avatar
jehan committed
297 298 299
#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));\
300
		}
301

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

jehan's avatar
jehan committed
304 305 306
#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) \
307
	type  object_type##_get_##attribute (const object_type##_t* obj) {\
jehan's avatar
jehan committed
308 309 310 311 312
		return obj->attribute;\
	}\
	void set_prefix##object_type##_set_##attribute (object_type##_t* obj,type  value) {\
		obj->attribute=value;\
	}
313 314 315 316 317
#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)
318
#define ATO_float(value) (float)strtod(value,NULL)
319 320 321 322 323 324
#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) \
325
	type  object_type##_get_##func_name (const object_type##_t* obj) {\
326 327
		const char* l_value = belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
		if (l_value == NULL) { \
jehan's avatar
jehan committed
328
			/*belle_sip_error("cannot find parameters [%s]",#attribute);*/\
329 330 331 332 333 334
			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];\
335 336 337 338
		if (value == -1) { \
			belle_sip_parameters_remove_parameter(BELLE_SIP_PARAMETERS(obj),#attribute);\
			return;\
		}\
339 340 341
		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
342 343

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

358 359 360 361 362 363 364 365 366
#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
367 368 369 370 371 372
#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; \
373
	belle_sip_##object_type##_t* l_parsed_object; \
374
	input  = ANTLR_STREAM_NEW(object_type,value,strlen(value));\
jehan's avatar
jehan committed
375 376 377
	lex    = belle_sip_messageLexerNew                (input);\
	tokens = antlr3CommonTokenStreamSourceNew  (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
	parser = belle_sip_messageParserNew               (tokens);\
378
	l_parsed_object = parser->object_type(parser);\
jehan's avatar
jehan committed
379 380 381 382
	parser ->free(parser);\
	tokens ->free(tokens);\
	lex    ->free(lex);\
	input  ->close(input);\
383
	if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
jehan's avatar
jehan committed
384 385 386
	return l_parsed_object;\
}

387 388 389
#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\
390 391 392
									, belle_sip_##super_type##_t\
									, belle_sip_##object_type##_destroy\
									, belle_sip_##object_type##_clone\
393
									, belle_sip_##object_type##_marshal, TRUE); \
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	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 () { \
411
		belle_sip_##object_type##_t* l_object = belle_sip_object_new(belle_sip_##object_type##_t);\
412
		belle_sip_##super_type##_init((belle_sip_##super_type##_t*)l_object); \
413
		belle_sip_##init_type##_init((belle_sip_##init_type##_t*) l_object); \
414
		if (name) belle_sip_header_set_name(BELLE_SIP_HEADER(l_object),name);\
415 416
		return l_object;\
	}
jehan's avatar
jehan committed
417 418 419 420 421 422 423 424 425
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);

426
void belle_sip_param_pair_destroy(belle_sip_param_pair_t*  pair) ;
jehan's avatar
jehan committed
427 428

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

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
436
void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t* address,const char* value);
jehan's avatar
jehan committed
437

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

jehan's avatar
jehan committed
446
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next);
447
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
448
void belle_sip_response_fill_for_dialog(belle_sip_response_t *obj, belle_sip_request_t *req);
449
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
450

jehan's avatar
jehan committed
451
void belle_sip_header_init(belle_sip_header_t* obj);
452 453
/*class parameters*/
struct _belle_sip_parameters {
jehan's avatar
jehan committed
454
	belle_sip_header_t base;
455 456 457 458 459 460
	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
461
/*
462
 * Listening points
Simon Morlat's avatar
Simon Morlat committed
463 464
*/

465
#include "listeningpoint_internal.h"
466

Simon Morlat's avatar
Simon Morlat committed
467 468 469

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


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

495
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
496
belle_sip_hop_t* belle_sip_hop_new_from_uri(const belle_sip_uri_t *uri);
497

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

/*
 belle_sip_provider_t
*/
504 505 506 507 508 509

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
510
	belle_sip_list_t *internal_listeners; /*for transaction internaly managed by belle-sip. I.E by refreshers*/
511
	belle_sip_list_t *client_transactions;
Simon Morlat's avatar
Simon Morlat committed
512
	belle_sip_list_t *server_transactions;
Simon Morlat's avatar
Simon Morlat committed
513
	belle_sip_list_t *dialogs;
514
	belle_sip_list_t *auth_contexts;
515 516
	unsigned char rport_enabled; /*0 if rport should not be set in via header*/
	unsigned char nat_helper;
517 518
};

519
belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
520 521 522
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
523 524 525 526
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);
527
void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, belle_sip_transaction_t *t);
528
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
529 530
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);
531
void belle_sip_provider_release_channel(belle_sip_provider_t *p, belle_sip_channel_t *chan);
532
void belle_sip_provider_add_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l, int prepend);
533
void belle_sip_provider_remove_internal_sip_listener(belle_sip_provider_t *p, belle_sip_listener_t *l);
534
belle_sip_client_transaction_t * belle_sip_provider_find_matching_client_transaction_from_req(belle_sip_provider_t *prov, belle_sip_request_t *req) ;
535 536
/*for testing purpose only:*/
void belle_sip_provider_dispatch_message(belle_sip_provider_t *prov, belle_sip_message_t *msg);
537

538 539 540 541 542
typedef struct listener_ctx{
	belle_sip_listener_t *listener;
	void *data;
}listener_ctx_t;

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

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

549

550 551 552 553 554 555 556 557 558 559 560 561
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*/
562
	char *rfc2543_branch; /*computed 'branch' id in case we receive this request from an old RFC2543 stack*/
563 564 565
	unsigned char dialog_queued;
};
	
566 567 568 569
/*
 belle_sip_transaction_t
*/

570 571 572 573
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;
574
	belle_sip_response_t *last_response;
575
	belle_sip_channel_t *channel;
Simon Morlat's avatar
Simon Morlat committed
576
	belle_sip_dialog_t *dialog;
577 578 579
	char *branch_id;
	belle_sip_transaction_state_t state;
	void *appdata;
580 581
	unsigned char is_internal;
	unsigned char timed_out; 
582 583
};

584 585 586 587 588

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

589
static BELLESIP_INLINE const belle_sip_timer_config_t * belle_sip_transaction_get_timer_config(belle_sip_transaction_t *obj){
590 591 592
	return belle_sip_stack_get_timer_config(obj->provider->stack);
}

593
static BELLESIP_INLINE void belle_sip_transaction_start_timer(belle_sip_transaction_t *obj, belle_sip_source_t *timer){
594 595
	belle_sip_main_loop_add_source(obj->provider->stack->ml,timer);
}
596
/** */
597
static BELLESIP_INLINE void belle_sip_transaction_stop_timer(belle_sip_transaction_t *obj, belle_sip_source_t *timer){
598 599 600 601
	belle_sip_main_loop_remove_source(obj->provider->stack->ml,timer);
}

void belle_sip_transaction_notify_timeout(belle_sip_transaction_t *t);
602

603 604
void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog);

605 606
void belle_sip_transaction_set_state(belle_sip_transaction_t *t, belle_sip_transaction_state_t state);

607 608 609 610 611 612 613 614 615 616
/*
 *
 *
 *	Client transaction
 *
 *
*/

struct belle_sip_client_transaction{
	belle_sip_transaction_t base;
617
	belle_sip_uri_t* preset_route; /*use to store outbound proxy, will be helpful for refresher*/
618
	belle_sip_hop_t* next_hop; /*use to send cancel request*/
619 620 621 622
};

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_client_transaction_t,belle_sip_transaction_t)
	void (*send_request)(belle_sip_client_transaction_t *);
623
	void (*on_response)(belle_sip_client_transaction_t *obj, belle_sip_response_t *resp);
624
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
625

626
void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, belle_sip_provider_t *prov, belle_sip_request_t *req);
627 628
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);
629

630 631
struct belle_sip_ict{
	belle_sip_client_transaction_t base;
632 633 634
	belle_sip_source_t *timer_A;
	belle_sip_source_t *timer_B;
	belle_sip_source_t *timer_D;
635
	belle_sip_source_t *timer_M;
636
	belle_sip_request_t *ack;
637 638 639 640 641 642 643 644 645 646 647
};

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;
648 649 650
	belle_sip_source_t *timer_F;
	belle_sip_source_t *timer_E;
	belle_sip_source_t *timer_K;
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
};

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;
671
	char to_tag[8];
672 673 674
};

BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_server_transaction_t,belle_sip_transaction_t)
675 676
	int (*send_new_response)(belle_sip_server_transaction_t *, belle_sip_response_t *resp);
	void (*on_request_retransmission)(belle_sip_server_transaction_t *obj);
677 678
BELLE_SIP_DECLARE_CUSTOM_VPTR_END

679
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
680
void belle_sip_server_transaction_on_request(belle_sip_server_transaction_t *t, belle_sip_request_t *req);
681

682 683
struct belle_sip_ist{
	belle_sip_server_transaction_t base;
684 685 686
	belle_sip_source_t *timer_G;
	belle_sip_source_t *timer_H;
	belle_sip_source_t *timer_I;
687
	belle_sip_source_t *timer_L;
688 689 690 691 692 693 694 695
};

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);
696 697
/* 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);
698 699 700

struct belle_sip_nist{
	belle_sip_server_transaction_t base;
701
	belle_sip_source_t *timer_J;
702 703 704 705 706 707 708 709 710
};

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
711 712 713 714 715 716

/*
 * Dialogs
 */ 
struct belle_sip_dialog{
	belle_sip_object_t base;
717
	void *appdata;
Simon Morlat's avatar
Simon Morlat committed
718 719
	belle_sip_provider_t *provider;
	belle_sip_request_t *last_out_invite;
720 721 722 723
	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
724
	belle_sip_dialog_state_t state;
jehan's avatar
jehan committed
725
	belle_sip_dialog_state_t previous_state;
Simon Morlat's avatar
Simon Morlat committed
726 727 728 729 730 731 732 733 734
	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;
735
	belle_sip_transaction_t* last_transaction;
jehan's avatar
jehan committed
736
	belle_sip_header_privacy_t* privacy;
737 738 739 740 741
	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
742 743 744
};

belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t);
jehan's avatar
jehan committed
745
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);
746
int belle_sip_dialog_is_authorized_transaction(const belle_sip_dialog_t *dialog,const char* method) ;
Simon Morlat's avatar
Simon Morlat committed
747 748 749
/*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);
750
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
751
void belle_sip_dialog_check_ack_sent(belle_sip_dialog_t*obj);
752
int belle_sip_dialog_handle_ack(belle_sip_dialog_t *obj, belle_sip_request_t *ack);
753
void belle_sip_dialog_queue_client_transaction(belle_sip_dialog_t *dialog, belle_sip_client_transaction_t *tr);
jehan's avatar
jehan committed
754

Simon Morlat's avatar
Simon Morlat committed
755 756 757
/*
 belle_sip_response_t
*/
758
belle_sip_hop_t* belle_sip_response_get_return_hop(belle_sip_response_t *msg);
Simon Morlat's avatar
Simon Morlat committed
759

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

765 766 767 768 769
#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
770 771 772 773 774 775 776 777 778
/*********************************************************
 * 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; \
779
	belle_sdp_##object_type##_t* l_parsed_object; \
780
	input  = ANTLR_STREAM_NEW(object_type, value,strlen(value));\
jehan's avatar
jehan committed
781 782 783
	lex    = belle_sdpLexerNew                (input);\
	tokens = antlr3CommonTokenStreamSourceNew  (ANTLR3_SIZE_HINT, TOKENSOURCE(lex));\
	parser = belle_sdpParserNew               (tokens);\
784
	l_parsed_object = parser->object_type(parser).ret;\
jehan's avatar
jehan committed
785 786 787 788 789 790 791 792
	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) \
793
		BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_##object_type##_t); \
jehan's avatar
jehan committed
794 795 796 797
		BELLE_SIP_INSTANCIATE_VPTR(	belle_sdp_##object_type##_t\
									, super_type##_t\
									, belle_sdp_##object_type##_destroy\
									, belle_sdp_##object_type##_clone\
798
									, belle_sdp_##object_type##_marshal, TRUE); \
jehan's avatar
jehan committed
799 800 801 802 803
		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
804
#define BELLE_SDP_NEW_WITH_CTR(object_type,super_type) \
805
		BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sdp_##object_type##_t); \
jehan's avatar
jehan committed
806 807 808 809
		BELLE_SIP_INSTANCIATE_VPTR(	belle_sdp_##object_type##_t\
									, super_type##_t\
									, belle_sdp_##object_type##_destroy\
									, belle_sdp_##object_type##_clone\
810
									, belle_sdp_##object_type##_marshal,TRUE); \
jehan's avatar
jehan committed
811 812 813 814 815 816
		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
817 818 819



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

struct belle_sip_io_error_event{
826
	belle_sip_object_t *source;  /*the object impacted by this error*/
jehan's avatar
jehan committed
827 828
	const char *transport;
	const char *host;
829
	unsigned int port;
jehan's avatar
jehan committed
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 856 857
};

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;
};

858
struct belle_sip_auth_event {
jehan's avatar
jehan committed
859 860
	belle_sip_auth_mode_t mode;

861 862 863 864 865
	char* username;
	char* userid;
	char* realm;
	char* passwd;
	char* ha1;
jehan's avatar
jehan committed
866 867 868 869 870

	const char* distinguished_name;
	belle_sip_certificates_chain_t * cert;
	belle_sip_signing_key_t* key;

871
};
jehan's avatar
jehan committed
872

873
belle_sip_auth_event_t* belle_sip_auth_event_create(const char* realm,const char* username);
jehan's avatar
jehan committed
874

jehan's avatar
jehan committed
875 876
void belle_sip_auth_event_set_distinguished_name(belle_sip_auth_event_t* event,const char* value);

jehan's avatar
jehan committed
877 878 879 880
/*
 * refresher
 * */
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction);
881

jehan's avatar
jehan committed
882

jehan's avatar
jehan committed
883 884 885
/*
 * returns a char, even if entry is escaped*/
int belle_sip_get_char (const char*a,int n,char*out);
886
/*return an escaped string*/
887 888
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
889

890 891

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

893 894 895
#define BELLE_SIP_BRANCH_ID_LENGTH 10
/*Shall not be less than 32bit */
#define BELLE_SIP_TAG_LENGTH 6
896
#define BELLE_SIP_MAX_TO_STRING_SIZE 2048
897

898
void belle_sip_header_contact_set_unknown(belle_sip_header_contact_t *a, int value);
899
void belle_sip_request_set_dialog(belle_sip_request_t *req, belle_sip_dialog_t *dialog);
900
void belle_sip_request_set_rfc2543_branch(belle_sip_request_t *req, const char *rfc2543branch);
901
void belle_sip_dialog_update_request(belle_sip_dialog_t *dialog, belle_sip_request_t *req);
902

jehan's avatar
jehan committed
903
#endif