1 /*
2   eXosip - This is the eXtended osip library.
3   Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
4 
5   eXosip is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9 
10   eXosip is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19   In addition, as a special exception, the copyright holders give
20   permission to link the code of portions of this program with the
21   OpenSSL library under certain conditions as described in each
22   individual source file, and distribute linked combinations
23   including the two.
24   You must obey the GNU General Public License in all respects
25   for all of the code used other than OpenSSL.  If you modify
26   file(s) with this exception, you may extend this exception to your
27   version of the file(s), but you are not obligated to do so.  If you
28   do not wish to do so, delete this exception statement from your
29   version.  If you delete this exception statement from all source
30   files in the program, then also delete it here.
31 */
32 
33 #ifndef __EXOSIP2_H__
34 #define __EXOSIP2_H__
35 
36 #if defined(HAVE_CONFIG_H)
37 #include <exosip-config.h>
38 #endif
39 
40 #define HAVE_INET_NTOP
41 
42 #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000)
43 #define HAVE_CTYPE_H 1
44 #define HAVE_STRING_H 1
45 #define HAVE_SYS_TYPES_H 1
46 #define HAVE_TIME_H 1
47 #define HAVE_STDARG_H 1
48 #define HAVE_MEMORY_H 1
49 #define HAVE_GMTIME 1
50 
51 #elif defined(__VXWORKS_OS__) || defined(__rtems__)
52 #define HAVE_STRING_H 1
53 #define HAVE_TIME_H 1
54 #define HAVE_SYS_TIME_H 1
55 #define HAVE_SYS_TYPES_H 1
56 #define HAVE_STDARG_H 1
57 #define HAVE_MEMORY_H 1
58 #define HAVE_GMTIME 1
59 
60 #elif defined(_WIN32_WCE)
61 
62 #define HAVE_WINDOWS_H 1
63 #define HAVE_WINSOCK2_H 1
64 #define HAVE_WS2TCPIP_H 1
65 #define HAVE_CTYPE_H 1
66 #define HAVE_STRING_H 1
67 #define HAVE_TIME_H 1
68 #define HAVE_STDARG_H 1
69 
70 #define snprintf _snprintf
71 
72 #undef HAVE_INET_NTOP
73 
74 #elif defined(WIN32)
75 
76 #define HAVE_WINDOWS_H 1
77 #define HAVE_WINSOCK2_H 1
78 #define HAVE_WS2TCPIP_H 1
79 #define HAVE_CTYPE_H 1
80 #define HAVE_STRING_H 1
81 #define HAVE_SYS_TYPES_H 1
82 #define HAVE_TIME_H 1
83 #define HAVE_STDARG_H 1
84 #define HAVE_SYS_STAT_H
85 
86 #if (_MSC_VER < 1900)
87 #define snprintf _snprintf
88 #endif
89 
90 /* use win32 crypto routines for random number generation */
91 /* only use for vs .net (compiler v. 1300) or greater */
92 #if _MSC_VER >= 1300
93 #define WIN32_USE_CRYPTO 1
94 #endif
95 
96 #if defined(_MSC_VER)
97 #define HAVE_MSTCPIP_H
98 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
99 #undef HAVE_MSTCPIP_H
100 #endif
101 #endif
102 
103 #define HAVE_WINCRYPT_H
104 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
105 #undef HAVE_WINCRYPT_H
106 #endif
107 
108 #if (_WIN32_WINNT >= 0x0600)
109 #define ENABLE_SIP_QOS
110 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)
111 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
112 #undef ENABLE_SIP_QOS
113 #endif
114 #endif
115 #endif
116 
117 #define HAVE_WINDNS_H
118 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
119 #undef HAVE_WINDNS_H
120 #endif
121 
122 #define HAVE_IPHLPAPI_H
123 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
124 #undef HAVE_IPHLPAPI_H
125 #endif
126 
127 #define HAVE_GMTIME 1
128 #undef HAVE_INET_NTOP
129 
130 #endif
131 
132 #if defined(__arc__)
133 #define HAVE_SYS_SOCKET_H
134 #define HAVE_NETINET_IN_H
135 #define HAVE_ARPA_INET_H
136 #endif
137 
138 #if defined(HAVE_STRING_H)
139 #include <string.h>
140 #elif defined(HAVE_STRINGS_H)
141 #include <strings.h>
142 #else
143 #include <string.h>
144 #endif
145 
146 #include <stdio.h>
147 #include <stdlib.h>
148 #if defined(HAVE_LIMITS_H)
149 #include <limits.h>
150 #endif
151 
152 #if defined(HAVE_SYS_TYPES_H)
153 #include <sys/types.h>
154 #endif
155 
156 #ifdef HAVE_TIME_H
157 #include <time.h>
158 #endif
159 
160 #if defined(HAVE_SYS_TIME_H)
161 #include <sys/time.h>
162 #endif
163 
164 #if defined(__arc__)
165 #include <posix_time_pub.h>
166 
167 #include "includes_api.h"
168 #include "os_cfg_pub.h"
169 #define USE_GETHOSTBYNAME
170 #endif
171 
172 #ifdef __PSOS__
173 #define VA_START(a, f) va_start(a, f)
174 #include "pna.h"
175 #include "stdlib.h"
176 #include "time.h"
177 #define timercmp(tvp, uvp, cmp) ((tvp)->tv_sec cmp(uvp)->tv_sec || (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp(uvp)->tv_usec)
178 #define snprintf osip_snprintf
179 #ifndef INT_MAX
180 #define INT_MAX 0x7FFFFFFF
181 #endif
182 #endif
183 
184 #ifdef HAVE_WINSOCK2_H
185 #include <winsock2.h>
186 #endif
187 
188 #ifdef HAVE_WS2TCPIP_H
189 #include <ws2tcpip.h>
190 #endif
191 
192 #ifdef HAVE_SYS_SOCKET_H
193 #include <sys/socket.h>
194 #endif
195 #ifdef HAVE_NETINET_IN_H
196 #include <netinet/in.h>
197 #endif
198 #ifdef HAVE_ARPA_INET_H
199 #include <arpa/inet.h>
200 #endif
201 #ifdef HAVE_NETDB_H
202 #include <netdb.h>
203 #endif
204 #ifdef HAVE_SYS_EPOLL_H
205 #include <sys/epoll.h>
206 #endif
207 
208 #include <eXosip2/eXosip.h>
209 #include <osip2/osip.h>
210 #include <osip2/osip_dialog.h>
211 
212 #include "eXtransport.h"
213 #include "jpipe.h"
214 
215 #define EXOSIP_VERSION "5.3.0"
216 
217 #ifdef HAVE_WINSOCK2_H
218 #define SOCKET_TYPE SOCKET
219 #else
220 #define SOCKET_TYPE int
221 #endif
222 
223 #if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L)
224 #include <stdint.h>
225 #elif defined(HAVE_STDINT_H)
226 #include <stdint.h>
227 #elif defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600)
228 typedef unsigned __int8 uint8_t;
229 typedef unsigned __int32 uint32_t;
230 typedef unsigned __int64 uint64_t;
231 #else
232 #include <stdint.h>
233 #endif
234 
235 #ifdef __cplusplus
236 extern "C" {
237 #endif
238 
239 /* I advise to use ERRBSIZ as a size */
240 #define ERRBSIZ 64
241 char *_ex_strerror(int errnum, char *buf, size_t buflen);
242 char *_ex_gai_strerror(int errnum, char *buf, size_t buflen);
243 
244 #if defined(USE_GETHOSTBYNAME)
245 
246 #define NI_MAXHOST 1025
247 #define NI_MAXSERV 32
248 #define NI_NUMERICHOST 1
249 
250 #ifndef PF_INET6
251 #define PF_INET6 AF_INET6
252 #endif
253 
254 #define _SS_MAXSIZE 128
255 #define _SS_ALIGNSIZE (sizeof(int64_t))
256 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned short))
257 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(unsigned short) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
258 struct sockaddr_storage {
259   unsigned short ss_family;
260   char _ss_pad1[_SS_PAD1SIZE];
261   int64_t _ss_align;
262   char _ss_pad2[_SS_PAD2SIZE];
263 };
264 
265 struct addrinfo {
266   int ai_flags;             /* Input flags.  */
267   int ai_family;            /* Protocol family for socket.  */
268   int ai_socktype;          /* Socket type.  */
269   int ai_protocol;          /* Protocol for socket.  */
270   socklen_t ai_addrlen;     /* Length of socket address.  */
271   struct sockaddr *ai_addr; /* Socket address for socket.  */
272   char *ai_canonname;       /* Canonical name for service location.  */
273   struct addrinfo *ai_next; /* Pointer to next in list.  */
274 };
275 
276 void _eXosip_freeaddrinfo(struct addrinfo *ai);
277 
278 #else
279 
280 #define _eXosip_freeaddrinfo freeaddrinfo
281 
282 #endif
283 
284 void _eXosip_update(struct eXosip_t *excontext);
285 void _eXosip_wakeup(struct eXosip_t *excontext);
286 
287 #ifndef DEFINE_SOCKADDR_STORAGE
288 #define __eXosip_sockaddr sockaddr_storage
289 #else
290 #define _SS_MAXSIZE 128
291 #define _SS_ALIGNSIZE (sizeof(int64_t))
292 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned short))
293 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(unsigned short) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
294 struct sockaddr_storage {
295   unsigned short ss_family;
296   char _ss_pad1[_SS_PAD1SIZE];
297   int64_t _ss_align;
298   char _ss_pad2[_SS_PAD2SIZE];
299 };
300 #endif
301 
302 typedef struct eXosip_dialog_t eXosip_dialog_t;
303 
304 struct eXosip_dialog_t {
305   int d_id;
306   osip_dialog_t *d_dialog; /* active dialog */
307 
308   time_t d_session_timer_start; /* session-timer helper */
309   int d_session_timer_length;
310   int d_refresher;
311   int d_session_timer_use_update;
312 
313   time_t d_timer;
314   int d_count;
315   osip_message_t *d_200Ok;
316   osip_message_t *d_ack;
317 
318   osip_list_t *d_inc_trs;
319   osip_list_t *d_out_trs;
320   int d_retry;   /* avoid too many unsuccessful retry */
321   int d_mincseq; /* remember cseq after PRACK and UPDATE during setup */
322 
323   time_t implicit_subscription_expire_time;
324 
325   eXosip_dialog_t *next;
326   eXosip_dialog_t *parent;
327 };
328 
329 typedef struct eXosip_call_t eXosip_call_t;
330 
331 struct eXosip_call_t {
332   int c_id;
333   eXosip_dialog_t *c_dialogs;
334   osip_transaction_t *c_inc_tr;
335   osip_transaction_t *c_out_tr;
336   osip_transaction_t *c_cancel_tr;
337   int c_retry; /* avoid too many unsuccessful retry */
338   void *external_reference;
339 
340   time_t expire_time;
341 
342   eXosip_call_t *next;
343   eXosip_call_t *parent;
344 };
345 
346 struct osip_stun {
347   uint16_t type;
348   uint16_t length;
349   uint32_t magic_cookie;
350   unsigned char tr_id[12];
351 };
352 
353 typedef struct eXosip_reg_t eXosip_reg_t;
354 
355 struct eXosip_reg_t {
356   int r_id;
357 
358   int r_reg_period; /* delay between registration (modified by server) */
359   int r_reg_expire; /* delay between registration (requested by client) */
360 
361   char *r_aor;       /* sip identity */
362   char *r_registrar; /* registrar */
363   char *r_contact;   /* list of contacts string */
364 
365   char r_line[16];   /* line identifier */
366   char r_qvalue[16]; /* the q value used for routing */
367 
368   osip_transaction_t *r_last_tr;
369   int r_retry;         /* avoid too many unsuccessful retry */
370   int r_retryfailover; /* avoid too many unsuccessful retry */
371   time_t r_retry_after_delay; /* obey to retry_after header */
372 #define RS_DELETIONREQUIRED 2
373 #define RS_DELETIONPROCEEDING 3
374 #define RS_MASQUERADINGREQUIRED 4
375 #define RS_MASQUERADINGPROCEEDING 5
376   int registration_step;  /* registration step for learning contact header binding */
377   time_t r_last_deletion; /* prevent loop for automasquerade: no more than one per minute. */
378 
379   /* used for STUN on UDP connections */
380   struct __eXosip_sockaddr stun_addr;
381   socklen_t stun_len;
382   struct osip_stun stun_binding;
383   char stun_ipbuf[INET6_ADDRSTRLEN];
384   uint16_t stun_nport;
385   time_t ping_rfc5626;
386   int pong_supported;
387 
388   eXosip_reg_t *next;
389   eXosip_reg_t *parent;
390 };
391 
392 #ifndef MINISIZE
393 
394 typedef struct eXosip_subscribe_t eXosip_subscribe_t;
395 
396 struct eXosip_subscribe_t {
397   int s_id;
398   int s_ss_status;
399   int s_ss_reason;
400   int s_reg_period;
401   eXosip_dialog_t *s_dialogs;
402 
403   int s_retry; /* avoid too many unsuccessful retry */
404   osip_transaction_t *s_inc_tr;
405   osip_transaction_t *s_out_tr;
406 
407   eXosip_subscribe_t *next;
408   eXosip_subscribe_t *parent;
409 };
410 
411 typedef struct eXosip_notify_t eXosip_notify_t;
412 
413 struct eXosip_notify_t {
414   int n_id;
415   int n_online_status;
416 
417   int n_ss_status;
418   int n_ss_reason;
419   time_t n_ss_expires;
420   eXosip_dialog_t *n_dialogs;
421 
422   osip_transaction_t *n_inc_tr;
423   osip_transaction_t *n_out_tr;
424 
425   eXosip_notify_t *next;
426   eXosip_notify_t *parent;
427 };
428 
429 typedef struct eXosip_pub_t eXosip_pub_t;
430 
431 struct eXosip_pub_t {
432   int p_id;
433 
434   int p_period;        /* delay between registration */
435   char p_aor[256];     /* sip identity */
436   char p_sip_etag[64]; /* sip_etag from 200ok */
437 
438   osip_transaction_t *p_last_tr;
439   int p_retry;
440   eXosip_pub_t *next;
441   eXosip_pub_t *parent;
442 };
443 
444 int _eXosip_pub_update(struct eXosip_t *excontext, eXosip_pub_t **pub, osip_transaction_t *tr, osip_message_t *answer);
445 int _eXosip_pub_find_by_aor(struct eXosip_t *excontext, eXosip_pub_t **pub, const char *aor);
446 int _eXosip_pub_find_by_tid(struct eXosip_t *excontext, eXosip_pub_t **pjp, int tid);
447 int _eXosip_pub_init(struct eXosip_t *excontext, eXosip_pub_t **pub, const char *aor, const char *exp);
448 void _eXosip_pub_free(struct eXosip_t *excontext, eXosip_pub_t *pub);
449 
450 #endif
451 
452 typedef struct jauthinfo_t jauthinfo_t;
453 
454 struct jauthinfo_t {
455   char username[50];
456   char userid[50];
457   char passwd[50];
458   char ha1[50];
459   char realm[50];
460   jauthinfo_t *parent;
461   jauthinfo_t *next;
462 };
463 
464 int _eXosip_create_proxy_authorization_header(osip_proxy_authenticate_t *wa, const char *rquri, const char *username, const char *passwd, const char *ha1, osip_proxy_authorization_t **auth, const char *method, const char *pszCNonce, int iNonceCount);
465 int _eXosip_store_nonce(struct eXosip_t *excontext, const char *call_id, osip_proxy_authenticate_t *wa, int answer_code);
466 int _eXosip_delete_nonce(struct eXosip_t *excontext, const char *call_id);
467 
468 eXosip_event_t *_eXosip_event_init_for_call(int type, eXosip_call_t *jc, eXosip_dialog_t *jd, osip_transaction_t *tr);
469 
470 #ifndef MINISIZE
471 eXosip_event_t *_eXosip_event_init_for_subscription(int type, eXosip_subscribe_t *js, eXosip_dialog_t *jd, osip_transaction_t *tr);
472 eXosip_event_t *_eXosip_event_init_for_notify(int type, eXosip_notify_t *jn, eXosip_dialog_t *jd, osip_transaction_t *tr);
473 #endif
474 
475 eXosip_event_t *_eXosip_event_init_for_reg(int type, eXosip_reg_t *jr, osip_transaction_t *tr);
476 eXosip_event_t *_eXosip_event_init_for_message(int type, osip_transaction_t *tr);
477 
478 int _eXosip_event_init(eXosip_event_t **je, int type);
479 void _eXosip_report_call_event(struct eXosip_t *excontext, int evt, eXosip_call_t *jc, eXosip_dialog_t *jd, osip_transaction_t *tr);
480 void _eXosip_report_event(struct eXosip_t *excontext, eXosip_event_t *je);
481 int _eXosip_event_add(struct eXosip_t *excontext, eXosip_event_t *je);
482 
483 typedef void (*eXosip_callback_t)(int type, eXosip_event_t *);
484 
485 char *_eXosip_strdup_printf(const char *fmt, ...);
486 
487 char *_eXosip_transport_protocol(osip_message_t *msg);
488 int _eXosip_find_protocol(osip_message_t *msg);
489 int setsockopt_ipv6only(int sock);
490 
491 #ifndef MAX_EXOSIP_DNS_ENTRY
492 #define MAX_EXOSIP_DNS_ENTRY 10
493 #endif
494 
495 #ifndef MAX_EXOSIP_ACCOUNT_INFO
496 #define MAX_EXOSIP_ACCOUNT_INFO 10
497 #endif
498 
499 #ifndef MAX_EXOSIP_HTTP_AUTH
500 #define MAX_EXOSIP_HTTP_AUTH 100
501 #endif
502 
503 #ifndef EXOSIP_RING_TIMEOUT
504 #define EXOSIP_RING_TIMEOUT 180
505 #endif
506 
507 struct eXosip_counters {
508   float current_average;
509   unsigned int num_entries;
510   unsigned short period;   /* total max duration */
511   unsigned short interval; /* minimum interval */
512   unsigned short *values;
513   struct timeval *times;
514   unsigned int index_last;
515   unsigned int total_values;
516 };
517 
518 typedef struct eXosip_t eXosip_t;
519 
520 struct eXosip_t {
521 #ifndef MINISIZE
522   struct eXosip_stats statistics;
523   struct eXosip_counters average_transactions;
524   struct eXosip_counters average_registrations;
525   struct eXosip_counters average_calls;
526   struct eXosip_counters average_publications;
527   struct eXosip_counters average_subscriptions;
528   struct eXosip_counters average_insubscriptions;
529 #endif
530 
531   struct eXtl_protocol eXtl_transport;
532   void *eXtludp_reserved;
533   void *eXtltcp_reserved;
534 #ifndef DISABLE_TLS
535   void *eXtltls_reserved;
536   void *eXtldtls_reserved;
537 #endif
538 
539 #define EXOSIP_USE_SELECT 0
540 #define EXOSIP_USE_EPOLL_LT 1
541 
542   int poll_method; /* EXOSIP_USE_SELECT EXOSIP_USE_EPOLL_LT */
543 
544 #ifndef EXOSIP_MAX_DESCRIPTOR
545 #define EXOSIP_MAX_DESCRIPTOR 10000
546 #endif
547 #ifdef HAVE_SYS_EPOLL_H
548   int max_fd_no;
549   int epfd; /* epoll ctrl fd */
550   struct epoll_event *ep_array;
551   int epfdctl; /* epoll ctrl fd for exosip wait/get events */
552 #endif
553 
554   char transport[10];
555   char *user_agent;
556 
557   eXosip_reg_t *j_reg;    /* my registrations */
558   eXosip_call_t *j_calls; /* my calls        */
559 #ifndef MINISIZE
560   eXosip_subscribe_t *j_subscribes; /* my friends      */
561   eXosip_notify_t *j_notifies;      /* my susbscribers */
562   eXosip_pub_t *j_pub;              /* my publications  */
563 #endif
564   osip_list_t j_transactions;
565 
566   osip_t *j_osip;
567   int j_stop_ua;
568 #ifndef OSIP_MONOTHREAD
569   void *j_cond;
570   void *j_mutexlock;
571   void *j_thread;
572   jpipe_t *j_socketctl;
573   jpipe_t *j_socketctl_event;
574 #endif
575   int max_message_to_read;
576   long int max_read_timeout;
577 
578   osip_fifo_t *j_events;
579 
580   jauthinfo_t *authinfos;
581 
582   struct timeval cc_timer;
583   struct timeval ka_timer;
584   int ka_interval;
585   char ka_crlf[5];
586   int ka_options;
587   int learn_port;
588   int use_rport;
589   int remove_prerouteset;
590   int dns_capabilities;
591   int enable_dns_cache;
592   int dscp;
593   int implicit_subscription_expires;
594   int register_with_date;
595   int autoanswer_bye;
596   int ipv6_enable;
597   char ipv4_for_gateway[256];
598   char ipv6_for_gateway[256];
599   struct eXosip_dns_cache dns_entries[MAX_EXOSIP_DNS_ENTRY];
600   struct eXosip_account_info account_entries[MAX_EXOSIP_ACCOUNT_INFO];
601   struct eXosip_http_auth http_auths[MAX_EXOSIP_HTTP_AUTH];
602 
603   /* udp pre-config */
604   char udp_firewall_ip[64];
605   char udp_firewall_port[10];
606 
607   /* tcp pre-config */
608   char tcp_firewall_ip[64];
609   char tcp_firewall_port[10];
610 
611   /* tls pre-config */
612   char tls_firewall_ip[64];
613   char tls_firewall_port[10];
614   int tls_verify_client_certificate;
615   eXosip_tls_ctx_t eXosip_tls_ctx_params;
616 
617   /* dtls pre-config */
618   char dtls_firewall_ip[64];
619   char dtls_firewall_port[10];
620 
621   CbSipCallback cbsipCallback;
622   int masquerade_via;
623   int auto_masquerade_contact;
624   int reuse_tcp_port;
625   int use_ephemeral_port;
626   int enable_outbound;
627   char oc_local_address[64];
628   int oc_local_port_range[2];
629   int oc_local_port_current;
630 
631   CbSipWakeLock cbsipWakeLock;
632   int outgoing_wake_lock_state;
633   int incoming_wake_lock_state;
634 
635   char sip_instance[256]; /* can only be used if ONE excontext is used for ONE registration only */
636   char co_register_extra_params[512]; /* some extra contact parameters for Contact in REGISTER "audio;video;mobility="fixed";+sip.message="TRUE";other-param=66372;" parameter must not contains initial ";" */
637   char co_dialog_extra_params[512];   /* some extra contact parameters for Contact in INVITE's dialog "audio;video;" parameter must not contains initial ";" */
638   char default_contact_displayname[256];
639   int opt_sessiontimers_force;
640   int opt_force_connectionreuse;
641 };
642 
643 int _eXosip_guess_ip_for_via(struct eXosip_t *excontext, int family, char *address, int size);
644 int _eXosip_guess_ip_for_destination(struct eXosip_t *excontext, int family, char *destination, char *address, int size);
645 int _eXosip_guess_ip_for_destinationsock(struct eXosip_t *excontext, int family, int proto, struct sockaddr_storage *udp_local_bind, int sock, char *destination, char *address, int size);
646 
647 int _eXosip_closesocket(SOCKET_TYPE sock);
648 int _eXosip_getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags);
649 int _eXosip_getport(const struct sockaddr *sa);
650 int _eXosip_get_addrinfo(struct eXosip_t *excontext, struct addrinfo **addrinfo, const char *hostname, int service, int protocol);
651 
652 int _eXosip_set_callbacks(osip_t *osip);
653 int _eXosip_snd_message(struct eXosip_t *excontext, osip_transaction_t *tr, osip_message_t *sip, char *host, int port, int out_socket);
654 char *_eXosip_malloc_new_random(void);
655 void _eXosip_delete_reserved(osip_transaction_t *transaction);
656 
657 int _eXosip_dialog_init_as_uac(eXosip_dialog_t **jd, osip_message_t *_200Ok);
658 int _eXosip_dialog_init_as_uas(eXosip_dialog_t **jd, osip_message_t *_invite, osip_message_t *_200Ok);
659 void _eXosip_dialog_free(struct eXosip_t *excontext, eXosip_dialog_t *jd);
660 
661 int _eXosip_generating_request_out_of_dialog(struct eXosip_t *excontext, osip_message_t **dest, const char *method, const char *to, const char *from, const char *proxy);
662 int _eXosip_generating_publish(struct eXosip_t *excontext, osip_message_t **message, const char *to, const char *from, const char *route);
663 int _eXosip_generating_cancel(struct eXosip_t *excontext, osip_message_t **dest, osip_message_t *request_cancelled);
664 int _eXosip_generating_bye(struct eXosip_t *excontext, osip_message_t **bye, osip_dialog_t *dialog);
665 int _eXosip_request_viamanager(struct eXosip_t *excontext, osip_message_t *sip, int family, int proto, struct sockaddr_storage *udp_local_bind, int local_port, int sock, char *host);
666 int _eXosip_message_contactmanager(struct eXosip_t *excontext, osip_message_t *sip, int family, int proto, struct sockaddr_storage *udp_local_bind, int local_port, int sock, char *host);
667 
668 int _eXosip_update_top_via(osip_message_t *sip);
669 int _eXosip_request_add_via(struct eXosip_t *excontext, osip_message_t *request);
670 
671 void _eXosip_mark_all_registrations_expired(struct eXosip_t *excontext);
672 void _eXosip_mark_all_transaction_force_send(struct eXosip_t *excontext, int socket);
673 void _eXosip_mark_all_transaction_transport_error(struct eXosip_t *excontext, int socket);
674 void _eXosip_mark_registration_expired(struct eXosip_t *excontext, const char *call_id);
675 int _eXosip_mark_all_transaction_ready(struct eXosip_t *excontext, fd_set *osip_fdset, fd_set *osip_wrset, fd_set *osip_exceptset, int *osip_fd_table);
676 #ifdef HAVE_SYS_EPOLL_H
677 int _eXosip_mark_all_transaction_ready_epoll(struct eXosip_t *excontext, int nfds, int *osip_fd_table);
678 #endif
679 int _eXosip_check_allow_header(eXosip_dialog_t *jd, osip_message_t *message);
680 
681 int _eXosip_add_authentication_information(struct eXosip_t *excontext, osip_message_t *req, osip_message_t *last_response);
682 int _eXosip_reg_find(struct eXosip_t *excontext, eXosip_reg_t **reg, osip_transaction_t *tr);
683 int _eXosip_reg_find_id(struct eXosip_t *excontext, eXosip_reg_t **reg, int rid);
684 int _eXosip_reg_init(struct eXosip_t *excontext, eXosip_reg_t **jr, const char *from, const char *proxy, const char *contact);
685 void _eXosip_reg_free(struct eXosip_t *excontext, eXosip_reg_t *jreg);
686 
687 int _eXosip_call_transaction_find(struct eXosip_t *excontext, int tid, eXosip_call_t **jc, eXosip_dialog_t **jd, osip_transaction_t **tr);
688 int _eXosip_call_retry_request(struct eXosip_t *excontext, eXosip_call_t *jc, eXosip_dialog_t *jd, osip_transaction_t *out_tr);
689 int _eXosip_transaction_find(struct eXosip_t *excontext, int tid, osip_transaction_t **transaction);
690 int _eXosip_call_dialog_find(struct eXosip_t *excontext, int jid, eXosip_call_t **jc, eXosip_dialog_t **jd);
691 int _eXosip_call_find(struct eXosip_t *excontext, int cid, eXosip_call_t **jc);
692 int _eXosip_dialog_set_200ok(eXosip_dialog_t *_jd, osip_message_t *_200Ok);
693 
694 int _eXosip_answer_invite_123456xx(struct eXosip_t *excontext, eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer, int send);
695 
696 int _eXosip_build_response_default(struct eXosip_t *excontext, osip_message_t **dest, osip_dialog_t *dialog, int status, osip_message_t *request);
697 int _eXosip_complete_answer_that_establish_a_dialog(struct eXosip_t *excontext, osip_message_t *response, osip_message_t *request);
698 int _eXosip_build_request_within_dialog(struct eXosip_t *excontext, osip_message_t **dest, const char *method, osip_dialog_t *dialog);
699 int _eXosip_remove_transaction_from_call(osip_transaction_t *tr, eXosip_call_t *jc);
700 
701 osip_transaction_t *_eXosip_find_last_transaction(eXosip_call_t *jc, eXosip_dialog_t *jd, const char *method);
702 osip_transaction_t *_eXosip_find_last_inc_transaction(eXosip_dialog_t *jd, const char *method);
703 osip_transaction_t *_eXosip_find_last_out_transaction(eXosip_call_t *jc, eXosip_dialog_t *jd, const char *method);
704 osip_transaction_t *_eXosip_find_last_invite(eXosip_call_t *jc, eXosip_dialog_t *jd);
705 osip_transaction_t *_eXosip_find_last_inc_invite(eXosip_call_t *jc, eXosip_dialog_t *jd);
706 osip_transaction_t *_eXosip_find_last_out_invite(eXosip_call_t *jc, eXosip_dialog_t *jd);
707 osip_transaction_t *_eXosip_find_previous_invite(eXosip_call_t *jc, eXosip_dialog_t *jd, osip_transaction_t *last_invite);
708 
709 int _eXosip_call_init(struct eXosip_t *excontext, eXosip_call_t **jc);
710 void _eXosip_call_renew_expire_time(eXosip_call_t *jc);
711 void _eXosip_call_free(struct eXosip_t *excontext, eXosip_call_t *jc);
712 void _eXosip_call_remove_dialog_reference_in_call(eXosip_call_t *jc, eXosip_dialog_t *jd);
713 int _eXosip_read_message(struct eXosip_t *excontext, int max_message_nb, int sec_max, int usec_max);
714 void _eXosip_release_terminated_calls(struct eXosip_t *excontext);
715 void _eXosip_release_terminated_registrations(struct eXosip_t *excontext);
716 void _eXosip_release_terminated_publications(struct eXosip_t *excontext);
717 
718 #ifndef MINISIZE
719 int _eXosip_insubscription_transaction_find(struct eXosip_t *excontext, int tid, eXosip_notify_t **jn, eXosip_dialog_t **jd, osip_transaction_t **tr);
720 int _eXosip_notify_dialog_find(struct eXosip_t *excontext, int nid, eXosip_notify_t **jn, eXosip_dialog_t **jd);
721 int _eXosip_subscription_transaction_find(struct eXosip_t *excontext, int tid, eXosip_subscribe_t **js, eXosip_dialog_t **jd, osip_transaction_t **tr);
722 int _eXosip_subscription_dialog_find(struct eXosip_t *excontext, int nid, eXosip_subscribe_t **js, eXosip_dialog_t **jd);
723 int _eXosip_insubscription_answer_1xx(struct eXosip_t *excontext, eXosip_notify_t *jc, eXosip_dialog_t *jd, int code);
724 int _eXosip_insubscription_answer_2xx(eXosip_notify_t *jn, eXosip_dialog_t *jd, int code);
725 int _eXosip_insubscription_answer_3456xx(struct eXosip_t *excontext, eXosip_notify_t *jn, eXosip_dialog_t *jd, int code);
726 osip_transaction_t *_eXosip_find_last_inc_notify(eXosip_dialog_t *jd);
727 osip_transaction_t *_eXosip_find_last_out_notify(eXosip_dialog_t *jd);
728 osip_transaction_t *_eXosip_find_last_inc_subscribe(eXosip_notify_t *jn, eXosip_dialog_t *jd);
729 osip_transaction_t *_eXosip_find_last_out_subscribe(eXosip_subscribe_t *js, eXosip_dialog_t *jd);
730 void _eXosip_release_terminated_subscriptions(struct eXosip_t *excontext);
731 void _eXosip_release_terminated_in_subscriptions(struct eXosip_t *excontext);
732 int _eXosip_subscription_init(struct eXosip_t *excontext, eXosip_subscribe_t **js);
733 void _eXosip_subscription_free(struct eXosip_t *excontext, eXosip_subscribe_t *js);
734 int _eXosip_subscription_set_refresh_interval(eXosip_subscribe_t *js, osip_message_t *inc_subscribe);
735 int _eXosip_subscription_send_request_with_credential(struct eXosip_t *excontext, eXosip_subscribe_t *js, eXosip_dialog_t *jd, osip_transaction_t *out_tr);
736 int _eXosip_subscription_automatic_refresh(struct eXosip_t *excontext, eXosip_subscribe_t *js, eXosip_dialog_t *jd, osip_transaction_t *out_tr);
737 int _eXosip_notify_init(struct eXosip_t *excontext, eXosip_notify_t **jn, osip_message_t *inc_subscribe);
738 void _eXosip_notify_free(struct eXosip_t *excontext, eXosip_notify_t *jn);
739 int _eXosip_notify_set_contact_info(eXosip_notify_t *jn, char *uri);
740 int _eXosip_notify_set_refresh_interval(eXosip_notify_t *jn, osip_message_t *inc_subscribe);
741 void _eXosip_notify_add_expires_in_2XX_for_subscribe(eXosip_notify_t *jn, osip_message_t *answer);
742 int _eXosip_insubscription_send_request_with_credential(struct eXosip_t *excontext, eXosip_notify_t *jn, eXosip_dialog_t *jd, osip_transaction_t *out_tr);
743 #endif
744 
745 int _eXosip_is_public_address(const char *addr);
746 
747 void _eXosip_retransmit_lost200ok(struct eXosip_t *excontext);
748 int _eXosip_dialog_add_contact(struct eXosip_t *excontext, osip_message_t *request);
749 
750 int _eXosip_transaction_init(struct eXosip_t *excontext, osip_transaction_t **transaction, osip_fsm_type_t ctx_type, osip_t *osip, osip_message_t *message);
751 void _eXosip_transaction_free(struct eXosip_t *excontext, osip_transaction_t *transaction);
752 
753 int _eXosip_srv_lookup(struct eXosip_t *excontext, osip_message_t *sip, osip_naptr_t **naptr_record);
754 const char *_eXosip_dnsutils_find_sni(struct eXosip_t *excontext, const char *hostname);
755 int _eXosip_dnsutils_getsock(struct eXosip_t *excontext, fd_set *read_fds, fd_set *write_fds);
756 int _eXosip_dnsutils_checksock(struct eXosip_t *excontext, fd_set *read_fds, fd_set *write_fds);
757 int _eXosip_dnsutils_checksock_epoll(struct eXosip_t *excontext, int nfds);
758 int _eXosip_dnsutils_addsock_epoll(struct eXosip_t *excontext, int *cares_fd_table);
759 int _eXosip_dnsutils_delsock_epoll(struct eXosip_t *excontext, int *cares_fd_table);
760 
761 int _eXosip_handle_incoming_message(struct eXosip_t *excontext, char *buf, size_t len, int socket, char *host, int port, char *received_host, int *rport_port);
762 
763 int _eXosip_transport_set_dscp(struct eXosip_t *excontext, int family, int sock);
764 
765 /**
766  * sets the parameters for the TLS context, which is used for encrypted connections
767  * @return  the eXosip_tls_ctx_error code
768  */
769 eXosip_tls_ctx_error eXosip_set_tls_ctx(struct eXosip_t *excontext, eXosip_tls_ctx_t *ctx);
770 
771 /**
772  * Configure to accept/reject self signed and expired certificates.
773  */
774 eXosip_tls_ctx_error eXosip_tls_verify_certificate(struct eXosip_t *excontext, int _tls_verify_client_certificate);
775 
776 /**
777  * Shared method for TCP and TLS
778  * check if a socket is connected or broken
779  */
780 int _tcptls_tl_is_connected(int epoll_method, int sock);
781 
782 /**
783  * Resolv destination using NAPTR/SRV record
784  */
785 int _tl_resolv_naptr_destination(struct eXosip_t *excontext, osip_transaction_t *tr, osip_message_t *sip, char **out_host, int *out_port, osip_naptr_t **out_naptr_record);
786 
787 #ifndef EXOSIP_STATS_PERIOD
788 #define EXOSIP_STATS_PERIOD 3600 /* default period in seconds */
789 #endif
790 #ifndef EXOSIP_STATS_INTERVAL
791 #define EXOSIP_STATS_INTERVAL 60 /* default interval in seconds */
792 #endif
793 
794 #ifndef MINISIZE
795 void _eXosip_counters_init(struct eXosip_counters *bw_stats, int period, int interval);
796 void _eXosip_counters_update(struct eXosip_counters *bw_stats, int nvalues, struct timeval *now);
797 void _eXosip_counters_free(struct eXosip_counters *bw_stats);
798 #else
799 #define _eXosip_counters_init(A, B, C)
800 #define _eXosip_counters_update(A, B, C)
801 #define _eXosip_counters_free(A)
802 #endif
803 
804 #ifdef __cplusplus
805 }
806 #endif
807 #endif
808