tport 1.13.17
Loading...
Searching...
No Matches
tport_internal.h
1/*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef TPORT_INTERNAL_H
27#define TPORT_INTERNAL_H
28
38#ifndef SU_H
39#include <sofia-sip/su.h>
40#endif
41
43#include <sofia-sip/su_strlst.h>
44
45#ifndef MSG_ADDR_H
46#include <sofia-sip/msg_addr.h>
47#endif
48#ifndef TPORT_H
49#include <sofia-sip/tport.h>
50#endif
51
52#if HAVE_SOFIA_STUN
53#include "sofia-sip/stun.h"
54#include "sofia-sip/stun_tag.h"
55#endif
56
58
59#ifndef SU_DEBUG
60#define SU_DEBUG 3
61#endif
62#define SU_LOG tport_log
63
64#include <sofia-sip/su_debug.h>
65
66#if !defined(MSG_NOSIGNAL) || defined(__CYGWIN__) || defined(SYMBIAN)
67#undef MSG_NOSIGNAL
68#define MSG_NOSIGNAL (0)
69#endif
70
71#if (_WIN32_WINNT >= 0x0600)
72#ifndef HAVE_MSG_TRUNC
73#define HAVE_MSG_TRUNC 1
74#endif
75#endif
76
77#if !HAVE_MSG_TRUNC
78#define MSG_TRUNC (0)
79#endif
80
81#ifndef NONE
82#ifndef _MSC_VER
83#define NONE ((void *)-1)
84#else
85#define NONE ((void *)(INT_PTR)-1)
86#endif
87#endif
88
89SOFIA_BEGIN_DECLS
90
91typedef struct tport_master tport_master_t;
92typedef struct tport_pending_s tport_pending_t;
93typedef struct tport_primary tport_primary_t;
94typedef struct tport_vtable tport_vtable_t;
95
96struct sigcomp_state_handler;
97struct sigcomp_algorithm;
98struct sigcomp_udvm;
99struct sigcomp_magic;
100struct sigcomp_compartment;
101
102typedef long unsigned LU; /* for printf() and friends */
103
105typedef struct {
106 unsigned tpp_mtu;
107 unsigned tpp_idle;
108 unsigned tpp_timeout;
109 unsigned tpp_socket_keepalive;
110 unsigned tpp_keepalive;
111 unsigned tpp_pingpong;
113 unsigned tpp_sigcomp_lifetime;
114 unsigned tpp_thrpsize;
116 unsigned tpp_thrprqsize;
117 unsigned tpp_qsize;
119 unsigned tpp_drop;
120 int tpp_tos;
122 unsigned tpp_conn_orient:1;
123 unsigned tpp_sdwn_error:1;
124 unsigned tpp_stun_server:1;
125 unsigned tpp_pong2ping:1;
127 unsigned :0;
128
129} tport_params_t;
130
131
139struct tport_s {
140 su_home_t tp_home[1];
142 ssize_t tp_refs;
144 unsigned tp_black:1;
146 unsigned tp_accepted:1;
147 unsigned tp_conn_orient:1;
148 unsigned tp_has_connection:1;
149 unsigned tp_reusable:1;
150 unsigned tp_closed : 1;
157 unsigned tp_recv_close:2;
159 unsigned tp_send_close:2;
160 unsigned tp_has_keepalive:1;
161 unsigned tp_has_stun_server:1;
162 unsigned tp_trunc:1;
163 unsigned tp_is_connected:1;
164 unsigned tp_verified:1;
165 unsigned tp_pre_framed:1;
166 unsigned:0;
167
168 tport_t *tp_left, *tp_right, *tp_dad;
170 tport_master_t *tp_master;
171 tport_primary_t *tp_pri;
173 tport_params_t *tp_params;
175 tp_magic_t *tp_magic;
177 su_timer_t *tp_timer;
179 su_time_t tp_ktime;
180 su_time_t tp_ptime;
181 su_time_t tp_ltime;
183 tp_name_t tp_name[1];
189 su_strlst_t *tp_subjects;
197#define tp_protoname tp_name->tpn_proto
198#define tp_canon tp_name->tpn_canon
199#define tp_host tp_name->tpn_host
200#define tp_port tp_name->tpn_port
201#define tp_ident tp_name->tpn_ident
202
203 su_socket_t tp_socket;
204 int tp_index;
205 int tp_events;
207 su_addrinfo_t tp_addrinfo[1];
208 su_sockaddr_t tp_addr[1];
209#define tp_addrlen tp_addrinfo->ai_addrlen
210
211 /* ==== Receive queue ================================================== */
212
213 msg_t *tp_msg;
214 msg_t const *tp_rlogged;
215 su_time_t tp_rtime;
216 unsigned short tp_ping;
218 /* ==== Pending messages =============================================== */
219
220 unsigned short tp_reported;
221 unsigned tp_plen;
222 unsigned tp_pused;
223 tport_pending_t *tp_pending;
224 tport_pending_t *tp_released;
226 /* ==== Send queue ===================================================== */
227
228 msg_t **tp_queue;
229 unsigned short tp_qhead;
231 msg_iovec_t *tp_unsent;
232 size_t tp_unsentlen;
234 msg_iovec_t *tp_iov;
235 size_t tp_iovlen;
237 msg_t const *tp_slogged;
238 su_time_t tp_stime;
240 /* ==== Extensions ===================================================== */
241
242 tport_compressor_t *tp_comp;
243
244 /* ==== Statistics ===================================================== */
245
246 struct {
247 uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
248 uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
249 } tp_stats;
250};
251
253struct tport_primary {
254 tport_t pri_primary[1];
255#if DOXYGEN_ONLY
256 su_home_t pri_home[1];
257#else
258#define pri_home pri_primary->tp_home
259#define pri_master pri_primary->tp_master
260#define pri_protoname pri_primary->tp_name->tpn_proto
261#endif
262 tport_vtable_t const
263 *pri_vtable;
264 int pri_public;
269 tport_primary_t *pri_next;
271 tport_t *pri_open;
272 tport_t *pri_closed;
274 unsigned pri_updating:1;
275 unsigned pri_natted:1;
276 unsigned pri_has_tls:1;
277 unsigned:0;
278
279 void *pri_stun_handle;
280
281 tport_params_t pri_params[1];
282};
283
285struct tport_master {
286 tport_t mr_master[1];
287#if DOXYGEN_ONLY
288 su_home_t mr_home[1];
289#else
290#define mr_home mr_master->tp_home
291#endif
292
293 int mr_stun_step_ready;
295 tp_stack_t *mr_stack;
297 const *mr_tpac;
298 int mr_log;
299 su_root_t *mr_root;
302 su_timer_t *mr_timer;
304 FILE *mr_dump_file;
305 char *mr_dump;
307 su_socket_t mr_capt_sock;
308 char *mr_capt_name;
309 su_addrinfo_t *mr_capt_src_addr;
310 tport_primary_t *mr_primaries;
311 unsigned mr_prot_ver; /* hep version */
312 unsigned mr_agent_id; /* agent version */
313
314 tport_params_t mr_params[1];
315
316 unsigned mr_boundserver:1;
317 unsigned mr_bindv6only:1;
318 unsigned :0;
319
320 /* Delivery context */
321 struct tport_delivery {
322 tport_t *d_tport;
323 msg_t *d_msg;
324 tp_name_t d_from[1];
325 tport_compressor_t *d_comp;
326 } mr_delivery[1];
327
328 tport_stun_server_t *mr_stun_server;
329
330#if 0
331 struct tport_nat_s {
332 int initialized;
333 int bound;
334 int stun_enabled;
335 char *external_ip_address;
336#if HAVE_UPNP || HAVE_SOFIA_STUN
337 int try_stun;
338#endif
339#if HAVE_UPNP
340#endif
341#if HAVE_SOFIA_STUN
342 tport_master_t *tport;
343 char *stun_server;
344 /* stun_socket_t *stun_socket; */
345 stun_handle_t *stun;
346 su_socket_t stun_socket;
347 su_sockaddr_t sockaddr;
348#endif
349 } mr_nat[1];
350#endif
351};
352
354struct tport_vtable
355{
356 char const *vtp_name;
357 enum tport_via vtp_public;
358
359 size_t vtp_pri_size; /* Size of primary tport */
360 int (*vtp_init_primary)(tport_primary_t *pri,
361 tp_name_t tpn[1],
362 su_addrinfo_t *ai, tagi_t const *,
363 char const **return_culprit);
364 void (*vtp_deinit_primary)(tport_primary_t *pri);
365 int (*vtp_wakeup_pri)(tport_primary_t *pri, int events);
366 tport_t *(*vtp_connect)(tport_primary_t *pri, su_addrinfo_t *ai,
367 tp_name_t const *tpn);
368
369 size_t vtp_secondary_size; /* Size of secondary tport */
370
371 int (*vtp_init_secondary)(tport_t *, int socket, int accepted,
372 char const **return_reason);
373 void (*vtp_deinit_secondary)(tport_t *);
374 void (*vtp_shutdown)(tport_t *, int how);
375 int (*vtp_set_events)(tport_t const *self);
376 int (*vtp_wakeup)(tport_t *self, int events);
377 int (*vtp_recv)(tport_t *self);
378 ssize_t (*vtp_send)(tport_t const *self, msg_t *msg,
379 msg_iovec_t iov[], size_t iovused);
380 void (*vtp_deliver)(tport_t *self, msg_t *msg, su_time_t now);
381 int (*vtp_prepare)(tport_t *self, msg_t *msg,
382 tp_name_t const *tpn,
383 struct sigcomp_compartment *cc,
384 unsigned mtu);
385 int (*vtp_keepalive)(tport_t *self, su_addrinfo_t const *ai,
386 tagi_t const *taglist);
387 int (*vtp_stun_response)(tport_t const *self,
388 void *msg, size_t msglen,
389 void *addr, socklen_t addrlen);
390 int (*vtp_next_secondary_timer)(tport_t *self, su_time_t *,
391 char const **return_why);
392 void (*vtp_secondary_timer)(tport_t *self, su_time_t);
393};
394
395int tport_register_type(tport_vtable_t const *vtp);
396
398su_inline int tport_is_connection_oriented(tport_t const *self)
399{
400 return self->tp_conn_orient;
401}
402
404su_inline int tport_has_connection(tport_t const *self)
405{
406 return self->tp_has_connection;
407}
408
409void tport_has_been_updated(tport_t *tport);
410
411int tport_primary_compression(tport_primary_t *pri,
412 char const *compression,
413 tagi_t const *tl);
414
415void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos);
416
417tport_t *tport_base_connect(tport_primary_t *pri,
418 su_addrinfo_t *ai,
419 su_addrinfo_t *name,
420 tp_name_t const *tpn);
421
422int tport_stream_init_primary(tport_primary_t *pri,
423 su_socket_t socket,
424 tp_name_t tpn[1],
425 su_addrinfo_t *ai,
426 tagi_t const *tags,
427 char const **return_reason);
428
429tport_t *tport_alloc_secondary(tport_primary_t *pri,
430 int socket,
431 int accepted,
432 char const **return_reason);
433
434int tport_accept(tport_primary_t *pri, int events);
435int tport_register_secondary(tport_t *self, su_wakeup_f wakeup, int events);
436void tport_zap_secondary(tport_t *self);
437
438int tport_set_secondary_timer(tport_t *self);
439void tport_base_timer(tport_t *self, su_time_t now);
440
441int tport_bind_socket(int socket,
442 su_addrinfo_t *ai,
443 char const **return_culprit);
444void tport_close(tport_t *self);
445int tport_shutdown0(tport_t *self, int how);
446
447int tport_has_queued(tport_t const *self);
448
449int tport_error_event(tport_t *self);
450void tport_recv_event(tport_t *self);
451void tport_send_event(tport_t *self);
452void tport_hup_event(tport_t *self);
453int tport_setname(tport_t *, char const *, su_addrinfo_t const *, char const *);
454
455int tport_wakeup(su_root_magic_t *magic, su_wait_t *w, tport_t *self);
456
457ssize_t tport_recv_iovec(tport_t const *self,
458 msg_t **mmsg,
459 msg_iovec_t iovec[msg_n_fragments], size_t N,
460 int exact);
461
462msg_t *tport_msg_alloc(tport_t const *self, usize_t size);
463
464int tport_prepare_and_send(tport_t *self, msg_t *msg,
465 tp_name_t const *tpn,
466 struct sigcomp_compartment *cc,
467 unsigned mtu);
468int tport_send_msg(tport_t *self, msg_t *msg,
469 tp_name_t const *tpn,
470 struct sigcomp_compartment *cc);
471
472void tport_send_queue(tport_t *self);
473
474void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
475 tport_compressor_t *comp,
476 su_time_t now);
477void tport_base_deliver(tport_t *self, msg_t *msg, su_time_t now);
478
479int tport_recv_error_report(tport_t *self);
480void tport_error_report(tport_t *self, int errcode,
481 su_sockaddr_t const *addr);
482
483int tport_open_log(tport_master_t *mr, tagi_t *tags);
484void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
485 char const *via, su_time_t now);
486void tport_dump_iovec(tport_t const *self, msg_t *msg,
487 size_t n, su_iovec_t const iov[], size_t iovused,
488 char const *what, char const *how);
489
490void tport_capt_msg(tport_t const *self, msg_t *msg, size_t n,
491 su_iovec_t const iov[], size_t iovused, char const *what);
492
493int tport_capt_msg_hepv2(tport_t const *self, msg_t *msg, size_t n,
494 su_iovec_t const iov[], size_t iovused, char const *what, char **buffer);
495
496int tport_capt_msg_hepv3(tport_t const *self, msg_t *msg, size_t n,
497 su_iovec_t const iov[], size_t iovused, char const *what, char **buffer);
498
499int tport_tcp_ping(tport_t *self, su_time_t now);
500int tport_tcp_pong(tport_t *self);
501
502extern tport_vtable_t const tport_udp_vtable;
503extern tport_vtable_t const tport_udp_client_vtable;
504
505int tport_udp_init_primary(tport_primary_t *,
506 tp_name_t tpn[1],
508 tagi_t const *,
509 char const **return_culprit);
510void tport_udp_deinit_primary(tport_primary_t *);
511int tport_recv_dgram(tport_t *self);
512ssize_t tport_send_dgram(tport_t const *self, msg_t *msg,
513 msg_iovec_t iov[], size_t iovused);
514int tport_udp_error(tport_t const *self, su_sockaddr_t name[1]);
515
516extern tport_vtable_t const tport_tcp_vtable;
517extern tport_vtable_t const tport_tcp_client_vtable;
518
519int tport_tcp_init_primary(tport_primary_t *,
520 tp_name_t tpn[1],
521 su_addrinfo_t *, tagi_t const *,
522 char const **return_culprit);
523int tport_tcp_init_client(tport_primary_t *,
524 tp_name_t tpn[1],
525 su_addrinfo_t *, tagi_t const *,
526 char const **return_culprit);
527int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
528 char const **return_reason);
529int tport_recv_stream(tport_t *self);
530ssize_t tport_send_stream(tport_t const *self, msg_t *msg,
531 msg_iovec_t iov[], size_t iovused);
532
533int tport_tcp_next_timer(tport_t *self, su_time_t *, char const **);
534void tport_tcp_timer(tport_t *self, su_time_t);
535
536int tport_next_recv_timeout(tport_t *, su_time_t *, char const **);
537void tport_recv_timeout_timer(tport_t *self, su_time_t now);
538
539int tport_next_keepalive(tport_t *self, su_time_t *, char const **);
540void tport_keepalive_timer(tport_t *self, su_time_t now);
541
542extern tport_vtable_t const tport_ws_vtable;
543extern tport_vtable_t const tport_ws_client_vtable;
544extern tport_vtable_t const tport_wss_vtable;
545extern tport_vtable_t const tport_wss_client_vtable;
546extern tport_vtable_t const tport_sctp_vtable;
547extern tport_vtable_t const tport_sctp_client_vtable;
548extern tport_vtable_t const tport_tls_vtable;
549extern tport_vtable_t const tport_tls_client_vtable;
550extern tport_vtable_t const tport_stun_vtable;
551extern tport_vtable_t const tport_http_connect_vtable;
552extern tport_vtable_t const tport_threadpool_vtable;
553
554typedef struct tport_descriptor_s {
555 char const *tpd_name;
556 tport_vtable_t *tpd_vtable;
557 su_addrinfo_t *tpd_hints;
558 int tpd_is_client_only;
559} tport_descriptor_t;
560
561typedef int const *(tport_set_f)(tport_master_t *mr,
562 tp_name_t const *tpn,
563 tagi_t const *taglist,
564 tport_descriptor_t **return_set,
565 int return_set_size);
566
567/* STUN plugin */
568
569int tport_init_stun_server(tport_master_t *mr, tagi_t const *tags);
570void tport_deinit_stun_server(tport_master_t *mr);
571int tport_recv_stun_dgram(tport_t const *self, msg_t **in_out_msg,
572 su_sockaddr_t *from, socklen_t fromlen);
573
574int tport_stun_server_add_socket(tport_t *tp);
575int tport_stun_server_remove_socket(tport_t *tp);
576
577void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
578void tport_recv_message(tport_t *self, msg_t *msg, int error);
579
580void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
581void tport_sent_message(tport_t *self, msg_t *msg, int error);
582
583/* ---------------------------------------------------------------------- */
584/* Compressor plugin */
585extern tport_comp_vtable_t const *tport_comp_vtable;
586
587char const *tport_canonize_comp(char const *comp);
588
589int tport_init_compressor(tport_t *,
590 char const *comp_name,
591 tagi_t const *tags);
592void tport_deinit_compressor(tport_t *);
593
594struct sigcomp_compartment *
595tport_sigcomp_assign_if_needed(tport_t *self,
596 struct sigcomp_compartment *cc);
597
598struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self);
599
600void tport_sigcomp_accept_incomplete(tport_t *self, msg_t *msg);
601
602int tport_recv_comp_dgram(tport_t const *self,
603 tport_compressor_t *sc,
604 msg_t **in_out_msg,
605 su_sockaddr_t *from,
606 socklen_t fromlen);
607
608ssize_t tport_send_comp(tport_t const *self,
609 msg_t *msg,
610 msg_iovec_t iov[],
611 size_t iovused,
612 struct sigcomp_compartment *cc,
613 tport_compressor_t *sc);
614
615SOFIA_END_DECLS
616
617#endif /* TPORT_INTERNAL_H */
Transport name.
Definition tport.h:156
Interface towards stack.
Definition tport.h:93
int su_socket_t
struct addrinfo su_addrinfo_t
SU_HOME_T su_home_t
#define su_inline
SU_U64_T uint64_t
struct su_root_t su_root_t
SU_ROOT_MAGIC_T su_root_magic_t
struct pollfd su_wait_t
struct su_timer_s su_timer_t
Transport interface.
TP_STACK_T tp_stack_t
Type of stack object.
Definition tport.h:71
TP_MAGIC_T tp_magic_t
Type of transport-protocol-specific context object.
Definition tport.h:78
Transport plugin interface.
TPORT_STUN_SERVER_T tport_stun_server_t
Safe type for tport server object.
Definition tport_plugins.h:43
tport_via
Define how the public transport connects to Internet.
Definition tport_tag.h:81

Sofia-SIP 1.13.17 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.