tport 1.12.11devel
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#define NONE ((void *)(intptr_t)-1)
83#endif
84
85SOFIA_BEGIN_DECLS
86
87typedef struct tport_master tport_master_t;
88typedef struct tport_pending_s tport_pending_t;
89typedef struct tport_primary tport_primary_t;
90typedef struct tport_vtable tport_vtable_t;
91
92struct sigcomp_state_handler;
93struct sigcomp_algorithm;
94struct sigcomp_udvm;
95struct sigcomp_magic;
96struct sigcomp_compartment;
97
98typedef long unsigned LU; /* for printf() and friends */
99
101typedef struct {
102 unsigned tpp_mtu;
103 unsigned tpp_idle;
104 unsigned tpp_timeout;
105 unsigned tpp_keepalive;
106 unsigned tpp_pingpong;
108 unsigned tpp_sigcomp_lifetime;
109 unsigned tpp_thrpsize;
111 unsigned tpp_thrprqsize;
112 unsigned tpp_qsize;
114 unsigned tpp_drop;
115 int tpp_tos;
117 unsigned tpp_conn_orient:1;
118 unsigned tpp_sdwn_error:1;
119 unsigned tpp_stun_server:1;
120 unsigned tpp_pong2ping:1;
122 unsigned :0;
123
124} tport_params_t;
125
126
134struct tport_s {
135 su_home_t tp_home[1];
137 unsigned tp_accepted:1;
138 unsigned tp_conn_orient:1;
139 unsigned tp_has_connection:1;
140 unsigned tp_reusable:1;
141 unsigned tp_closed : 1;
148 unsigned tp_recv_close:2;
150 unsigned tp_send_close:2;
151 unsigned tp_has_keepalive:1;
152 unsigned tp_has_stun_server:1;
153 unsigned tp_trunc:1;
154 unsigned tp_is_connected:1;
155 unsigned tp_verified:1;
156 unsigned tp_error_reported:1;
158 /* Red-black tree */
159 unsigned tp_black:1;
160 unsigned:0;
161 tport_t *tp_left, *tp_right, *tp_dad;
163 tport_master_t *tp_master;
164 tport_primary_t *tp_pri;
166 tport_params_t *tp_params;
168 tp_magic_t *tp_magic;
170 su_timer_t *tp_timer;
172 su_time_t tp_ktime;
173 su_time_t tp_ptime;
175 tp_name_t tp_name[1];
181 su_strlst_t *tp_subjects;
189#define tp_protoname tp_name->tpn_proto
190#define tp_canon tp_name->tpn_canon
191#define tp_host tp_name->tpn_host
192#define tp_port tp_name->tpn_port
193#define tp_ident tp_name->tpn_ident
194
195 su_socket_t tp_socket;
196 int tp_index;
197 int tp_events;
199 su_addrinfo_t tp_addrinfo[1];
200 su_sockaddr_t tp_addr[1];
201#define tp_addrlen tp_addrinfo->ai_addrlen
202
203 /* ==== Receive queue ================================================== */
204
205 msg_t *tp_msg;
206 msg_t const *tp_rlogged;
207 su_time_t tp_rtime;
208 unsigned short tp_ping;
210 /* ==== Pending messages =============================================== */
211
212 unsigned short tp_reported;
213 unsigned tp_plen;
214 unsigned tp_pused;
215 tport_pending_t *tp_pending;
216 tport_pending_t *tp_released;
218 /* ==== Send queue ===================================================== */
219
220 msg_t **tp_queue;
221 unsigned short tp_qhead;
223 msg_iovec_t *tp_unsent;
224 size_t tp_unsentlen;
226 msg_iovec_t *tp_iov;
227 size_t tp_iovlen;
229 msg_t const *tp_slogged;
230 su_time_t tp_stime;
232 /* ==== Extensions ===================================================== */
233
234 tport_compressor_t *tp_comp;
235
236 /* ==== Statistics ===================================================== */
237
238 struct {
239 uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
240 uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
241 } tp_stats;
242};
243
245struct tport_primary {
246 tport_t pri_primary[1];
247#if DOXYGEN_ONLY
248 su_home_t pri_home[1];
249#else
250#define pri_home pri_primary->tp_home
251#define pri_master pri_primary->tp_master
252#define pri_protoname pri_primary->tp_name->tpn_proto
253#endif
254 tport_vtable_t const
255 *pri_vtable;
256 int pri_public;
261 tport_primary_t *pri_next;
263 tport_t *pri_open;
264 tport_t *pri_closed;
266 unsigned pri_updating:1;
267 unsigned pri_natted:1;
268 unsigned pri_has_tls:1;
269 unsigned:0;
270
271 void *pri_stun_handle;
272
273 tport_params_t pri_params[1];
274};
275
277struct tport_master {
278 tport_t mr_master[1];
279#if DOXYGEN_ONLY
280 su_home_t mr_home[1];
281#else
282#define mr_home mr_master->tp_home
283#endif
284
285 int mr_stun_step_ready;
287 tp_stack_t *mr_stack;
289 const *mr_tpac;
290 int mr_log;
291 su_root_t *mr_root;
294 su_timer_t *mr_timer;
296 FILE *mr_dump_file;
297 char *mr_dump;
298 tport_primary_t *mr_primaries;
300 tport_params_t mr_params[1];
301
302 unsigned mr_boundserver:1;
303 unsigned mr_bindv6only:1;
304 unsigned :0;
305
306 /* Delivery context */
307 struct tport_delivery {
308 tport_t *d_tport;
309 msg_t *d_msg;
310 tp_name_t d_from[1];
311 tport_compressor_t *d_comp;
312 } mr_delivery[1];
313
314 tport_stun_server_t *mr_stun_server;
315
316#if 0
317 struct tport_nat_s {
318 int initialized;
319 int bound;
320 int stun_enabled;
321 char *external_ip_address;
322#if HAVE_UPNP || HAVE_SOFIA_STUN
323 int try_stun;
324#endif
325#if HAVE_UPNP
326#endif
327#if HAVE_SOFIA_STUN
328 tport_master_t *tport;
329 char *stun_server;
330 /* stun_socket_t *stun_socket; */
331 stun_handle_t *stun;
332 su_socket_t stun_socket;
333 su_sockaddr_t sockaddr;
334#endif
335 } mr_nat[1];
336#endif
337};
338
340struct tport_vtable
341{
342 char const *vtp_name;
343 enum tport_via vtp_public;
344
345 size_t vtp_pri_size; /* Size of primary tport */
346 int (*vtp_init_primary)(tport_primary_t *pri,
347 tp_name_t tpn[1],
348 su_addrinfo_t *ai, tagi_t const *,
349 char const **return_culprit);
350 void (*vtp_deinit_primary)(tport_primary_t *pri);
351 int (*vtp_wakeup_pri)(tport_primary_t *pri, int events);
352 tport_t *(*vtp_connect)(tport_primary_t *pri, su_addrinfo_t *ai,
353 tp_name_t const *tpn);
354
355 size_t vtp_secondary_size; /* Size of secondary tport */
356
357 int (*vtp_init_secondary)(tport_t *, int socket, int accepted,
358 char const **return_reason);
359 void (*vtp_deinit_secondary)(tport_t *);
360 void (*vtp_shutdown)(tport_t *, int how);
361 int (*vtp_set_events)(tport_t const *self);
362 int (*vtp_wakeup)(tport_t *self, int events);
363 int (*vtp_recv)(tport_t *self);
364 ssize_t (*vtp_send)(tport_t const *self, msg_t *msg,
365 msg_iovec_t iov[], size_t iovused);
366 void (*vtp_deliver)(tport_t *self, msg_t *msg, su_time_t now);
367 int (*vtp_prepare)(tport_t *self, msg_t *msg,
368 tp_name_t const *tpn,
369 struct sigcomp_compartment *cc,
370 unsigned mtu);
371 int (*vtp_keepalive)(tport_t *self, su_addrinfo_t const *ai,
372 tagi_t const *taglist);
373 int (*vtp_stun_response)(tport_t const *self,
374 void *msg, size_t msglen,
375 void *addr, socklen_t addrlen);
376 int (*vtp_next_secondary_timer)(tport_t *self, su_time_t *,
377 char const **return_why);
378 void (*vtp_secondary_timer)(tport_t *self, su_time_t);
379};
380
381int tport_register_type(tport_vtable_t const *vtp);
382
384su_inline int tport_is_connection_oriented(tport_t const *self)
385{
386 return self->tp_conn_orient;
387}
388
390su_inline int tport_has_connection(tport_t const *self)
391{
392 return self->tp_has_connection;
393}
394
395void tport_has_been_updated(tport_t *tport);
396
397int tport_primary_compression(tport_primary_t *pri,
398 char const *compression,
399 tagi_t const *tl);
400
401void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos);
402
403tport_t *tport_base_connect(tport_primary_t *pri,
404 su_addrinfo_t *ai,
405 su_addrinfo_t *name,
406 tp_name_t const *tpn);
407
408int tport_stream_init_primary(tport_primary_t *pri,
409 su_socket_t socket,
410 tp_name_t tpn[1],
411 su_addrinfo_t *ai,
412 tagi_t const *tags,
413 char const **return_reason);
414
415tport_t *tport_alloc_secondary(tport_primary_t *pri,
416 int socket,
417 int accepted,
418 char const **return_reason);
419
420int tport_accept(tport_primary_t *pri, int events);
421int tport_register_secondary(tport_t *self, su_wakeup_f wakeup, int events);
422void tport_zap_secondary(tport_t *self);
423
424int tport_set_secondary_timer(tport_t *self);
425void tport_base_timer(tport_t *self, su_time_t now);
426
427int tport_bind_socket(int socket,
428 su_addrinfo_t *ai,
429 char const **return_culprit);
430void tport_close(tport_t *self);
431int tport_shutdown0(tport_t *self, int how);
432
433int tport_has_queued(tport_t const *self);
434
435int tport_error_event(tport_t *self);
436void tport_recv_event(tport_t *self);
437void tport_send_event(tport_t *self);
438void tport_hup_event(tport_t *self);
439int tport_setname(tport_t *, char const *, su_addrinfo_t const *, char const *);
440
441int tport_wakeup(su_root_magic_t *magic, su_wait_t *w, tport_t *self);
442
443ssize_t tport_recv_iovec(tport_t const *self,
444 msg_t **mmsg,
445 msg_iovec_t iovec[msg_n_fragments], size_t N,
446 int exact);
447
448msg_t *tport_msg_alloc(tport_t const *self, usize_t size);
449
450int tport_prepare_and_send(tport_t *self, msg_t *msg,
451 tp_name_t const *tpn,
452 struct sigcomp_compartment *cc,
453 unsigned mtu);
454int tport_send_msg(tport_t *self, msg_t *msg,
455 tp_name_t const *tpn,
456 struct sigcomp_compartment *cc);
457
458void tport_send_queue(tport_t *self);
459
460void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
461 tport_compressor_t *comp,
462 su_time_t now);
463void tport_base_deliver(tport_t *self, msg_t *msg, su_time_t now);
464
465int tport_recv_error_report(tport_t *self);
466void tport_error_report(tport_t *self, int errcode,
467 su_sockaddr_t const *addr);
468
469int tport_open_log(tport_master_t *mr, tagi_t *tags);
470void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
471 char const *via, su_time_t now);
472void tport_dump_iovec(tport_t const *self, msg_t *msg,
473 size_t n, su_iovec_t const iov[], size_t iovused,
474 char const *what, char const *how);
475
476int tport_tcp_ping(tport_t *self, su_time_t now);
477int tport_tcp_pong(tport_t *self);
478
479extern tport_vtable_t const tport_udp_vtable;
480extern tport_vtable_t const tport_udp_client_vtable;
481
482int tport_udp_init_primary(tport_primary_t *,
483 tp_name_t tpn[1],
485 tagi_t const *,
486 char const **return_culprit);
487void tport_udp_deinit_primary(tport_primary_t *);
488int tport_recv_dgram(tport_t *self);
489ssize_t tport_send_dgram(tport_t const *self, msg_t *msg,
490 msg_iovec_t iov[], size_t iovused);
491int tport_udp_error(tport_t const *self, su_sockaddr_t name[1]);
492
493extern tport_vtable_t const tport_tcp_vtable;
494extern tport_vtable_t const tport_tcp_client_vtable;
495
496int tport_tcp_init_primary(tport_primary_t *,
497 tp_name_t tpn[1],
498 su_addrinfo_t *, tagi_t const *,
499 char const **return_culprit);
500int tport_tcp_init_client(tport_primary_t *,
501 tp_name_t tpn[1],
502 su_addrinfo_t *, tagi_t const *,
503 char const **return_culprit);
504int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
505 char const **return_reason);
506int tport_recv_stream(tport_t *self);
507ssize_t tport_send_stream(tport_t const *self, msg_t *msg,
508 msg_iovec_t iov[], size_t iovused);
509
510int tport_tcp_next_timer(tport_t *self, su_time_t *, char const **);
511void tport_tcp_timer(tport_t *self, su_time_t);
512
513int tport_next_recv_timeout(tport_t *, su_time_t *, char const **);
514void tport_recv_timeout_timer(tport_t *self, su_time_t now);
515
516int tport_next_keepalive(tport_t *self, su_time_t *, char const **);
517void tport_keepalive_timer(tport_t *self, su_time_t now);
518
519extern tport_vtable_t const tport_sctp_vtable;
520extern tport_vtable_t const tport_sctp_client_vtable;
521extern tport_vtable_t const tport_tls_vtable;
522extern tport_vtable_t const tport_tls_client_vtable;
523extern tport_vtable_t const tport_stun_vtable;
524extern tport_vtable_t const tport_http_connect_vtable;
525extern tport_vtable_t const tport_threadpool_vtable;
526
527typedef struct tport_descriptor_s {
528 char const *tpd_name;
529 tport_vtable_t *tpd_vtable;
530 su_addrinfo_t *tpd_hints;
531 int tpd_is_client_only;
532} tport_descriptor_t;
533
534typedef int const *(tport_set_f)(tport_master_t *mr,
535 tp_name_t const *tpn,
536 tagi_t const *taglist,
537 tport_descriptor_t **return_set,
538 int return_set_size);
539
540/* STUN plugin */
541
542int tport_init_stun_server(tport_master_t *mr, tagi_t const *tags);
543void tport_deinit_stun_server(tport_master_t *mr);
544int tport_recv_stun_dgram(tport_t const *self, msg_t **in_out_msg,
545 su_sockaddr_t *from, socklen_t fromlen);
546
547int tport_stun_server_add_socket(tport_t *tp);
548int tport_stun_server_remove_socket(tport_t *tp);
549
550void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
551void tport_recv_message(tport_t *self, msg_t *msg, int error);
552
553void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
554void tport_sent_message(tport_t *self, msg_t *msg, int error);
555
556/* ---------------------------------------------------------------------- */
557/* Compressor plugin */
558extern tport_comp_vtable_t const *tport_comp_vtable;
559
560char const *tport_canonize_comp(char const *comp);
561
562int tport_init_compressor(tport_t *,
563 char const *comp_name,
564 tagi_t const *tags);
565void tport_deinit_compressor(tport_t *);
566
567struct sigcomp_compartment *
568tport_sigcomp_assign_if_needed(tport_t *self,
569 struct sigcomp_compartment *cc);
570
571struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self);
572
573void tport_sigcomp_accept_incomplete(tport_t *self, msg_t *msg);
574
575int tport_recv_comp_dgram(tport_t const *self,
576 tport_compressor_t *sc,
577 msg_t **in_out_msg,
578 su_sockaddr_t *from,
579 socklen_t fromlen);
580
581ssize_t tport_send_comp(tport_t const *self,
582 msg_t *msg,
583 msg_iovec_t iov[],
584 size_t iovused,
585 struct sigcomp_compartment *cc,
586 tport_compressor_t *sc);
587
588SOFIA_END_DECLS
589
590#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.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.