00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef TPORT_INTERNAL_H
00026
00027 #define TPORT_INTERNAL_H
00028
00038 #ifndef SU_H
00039 #include <sofia-sip/su.h>
00040 #endif
00041
00042 #include <sofia-sip/su_uniqueid.h>
00043 #include <sofia-sip/su_strlst.h>
00044
00045 #ifndef MSG_ADDR_H
00046 #include <sofia-sip/msg_addr.h>
00047 #endif
00048 #ifndef TPORT_H
00049 #include <sofia-sip/tport.h>
00050 #endif
00051
00052 #if HAVE_SOFIA_STUN
00053 #include "sofia-sip/stun.h"
00054 #include "sofia-sip/stun_tag.h"
00055 #endif
00056
00057 #include <sofia-sip/tport_plugins.h>
00058
00059 #ifndef SU_DEBUG
00060 #define SU_DEBUG 3
00061 #endif
00062 #define SU_LOG tport_log
00063
00064 #include <sofia-sip/su_debug.h>
00065
00066 #if !defined(MSG_NOSIGNAL) || defined(__CYGWIN__) || defined(SYMBIAN)
00067 #undef MSG_NOSIGNAL
00068 #define MSG_NOSIGNAL (0)
00069 #endif
00070
00071 #if (_WIN32_WINNT >= 0x0600)
00072 #ifndef HAVE_MSG_TRUNC
00073 #define HAVE_MSG_TRUNC 1
00074 #endif
00075 #endif
00076
00077 #if !HAVE_MSG_TRUNC
00078 #define MSG_TRUNC (0)
00079 #endif
00080
00081 #ifndef NONE
00082 #define NONE ((void *)-1)
00083 #endif
00084
00085 SOFIA_BEGIN_DECLS
00086
00087 typedef struct tport_master tport_master_t;
00088 typedef struct tport_pending_s tport_pending_t;
00089 typedef struct tport_primary tport_primary_t;
00090 typedef struct tport_vtable tport_vtable_t;
00091
00092 struct sigcomp_state_handler;
00093 struct sigcomp_algorithm;
00094 struct sigcomp_udvm;
00095 struct sigcomp_magic;
00096 struct sigcomp_compartment;
00097
00098 typedef long unsigned LU;
00099
00101 typedef struct {
00102 unsigned tpp_mtu;
00103 unsigned tpp_idle;
00104 unsigned tpp_timeout;
00105 unsigned tpp_keepalive;
00106 unsigned tpp_pingpong;
00108 unsigned tpp_sigcomp_lifetime;
00109 unsigned tpp_thrpsize;
00111 unsigned tpp_thrprqsize;
00112 unsigned tpp_qsize;
00114 unsigned tpp_drop;
00115 int tpp_tos;
00117 unsigned tpp_conn_orient:1;
00118 unsigned tpp_sdwn_error:1;
00119 unsigned tpp_stun_server:1;
00120 unsigned tpp_pong2ping:1;
00122 unsigned :0;
00123
00124 } tport_params_t;
00125
00126
00134 struct tport_s {
00135 su_home_t tp_home[1];
00137 ssize_t tp_refs;
00139 unsigned tp_black:1;
00141 unsigned tp_accepted:1;
00142 unsigned tp_conn_orient:1;
00143 unsigned tp_has_connection:1;
00144 unsigned tp_reusable:1;
00145 unsigned tp_closed : 1;
00152 unsigned tp_recv_close:2;
00154 unsigned tp_send_close:2;
00155 unsigned tp_has_keepalive:1;
00156 unsigned tp_has_stun_server:1;
00157 unsigned tp_trunc:1;
00158 unsigned tp_is_connected:1;
00159 unsigned tp_verified:1;
00160 unsigned:0;
00161
00162 tport_t *tp_left, *tp_right, *tp_dad;
00164 tport_master_t *tp_master;
00165 tport_primary_t *tp_pri;
00167 tport_params_t *tp_params;
00169 tp_magic_t *tp_magic;
00171 su_timer_t *tp_timer;
00173 su_time_t tp_ktime;
00174 su_time_t tp_ptime;
00176 tp_name_t tp_name[1];
00182 su_strlst_t *tp_subjects;
00190 #define tp_protoname tp_name->tpn_proto
00191 #define tp_canon tp_name->tpn_canon
00192 #define tp_host tp_name->tpn_host
00193 #define tp_port tp_name->tpn_port
00194 #define tp_ident tp_name->tpn_ident
00195
00196 su_socket_t tp_socket;
00197 int tp_index;
00198 int tp_events;
00200 su_addrinfo_t tp_addrinfo[1];
00201 su_sockaddr_t tp_addr[1];
00202 #define tp_addrlen tp_addrinfo->ai_addrlen
00203
00204
00205
00206 msg_t *tp_msg;
00207 msg_t const *tp_rlogged;
00208 su_time_t tp_rtime;
00209 unsigned short tp_ping;
00211
00212
00213 unsigned short tp_reported;
00214 unsigned tp_plen;
00215 unsigned tp_pused;
00216 tport_pending_t *tp_pending;
00217 tport_pending_t *tp_released;
00219
00220
00221 msg_t **tp_queue;
00222 unsigned short tp_qhead;
00224 msg_iovec_t *tp_unsent;
00225 size_t tp_unsentlen;
00227 msg_iovec_t *tp_iov;
00228 size_t tp_iovlen;
00230 msg_t const *tp_slogged;
00231 su_time_t tp_stime;
00233
00234
00235 tport_compressor_t *tp_comp;
00236
00237
00238
00239 struct {
00240 uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
00241 uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
00242 } tp_stats;
00243 };
00244
00246 struct tport_primary {
00247 tport_t pri_primary[1];
00248 #if DOXYGEN_ONLY
00249 su_home_t pri_home[1];
00250 #else
00251 #define pri_home pri_primary->tp_home
00252 #define pri_master pri_primary->tp_master
00253 #define pri_protoname pri_primary->tp_name->tpn_proto
00254 #endif
00255 tport_vtable_t const
00256 *pri_vtable;
00257 int pri_public;
00262 tport_primary_t *pri_next;
00264 tport_t *pri_open;
00265 tport_t *pri_closed;
00267 unsigned pri_updating:1;
00268 unsigned pri_natted:1;
00269 unsigned pri_has_tls:1;
00270 unsigned:0;
00271
00272 void *pri_stun_handle;
00273
00274 tport_params_t pri_params[1];
00275 };
00276
00278 struct tport_master {
00279 tport_t mr_master[1];
00280 #if DOXYGEN_ONLY
00281 su_home_t mr_home[1];
00282 #else
00283 #define mr_home mr_master->tp_home
00284 #endif
00285
00286 int mr_stun_step_ready;
00288 tp_stack_t *mr_stack;
00289 tp_stack_class_t
00290 const *mr_tpac;
00291 int mr_log;
00292 su_root_t *mr_root;
00295 su_timer_t *mr_timer;
00297 FILE *mr_dump_file;
00298 char *mr_dump;
00299 tport_primary_t *mr_primaries;
00301 tport_params_t mr_params[1];
00302
00303 unsigned mr_boundserver:1;
00304 unsigned mr_bindv6only:1;
00305 unsigned :0;
00306
00307
00308 struct tport_delivery {
00309 tport_t *d_tport;
00310 msg_t *d_msg;
00311 tp_name_t d_from[1];
00312 tport_compressor_t *d_comp;
00313 } mr_delivery[1];
00314
00315 tport_stun_server_t *mr_stun_server;
00316
00317 #if 0
00318 struct tport_nat_s {
00319 int initialized;
00320 int bound;
00321 int stun_enabled;
00322 char *external_ip_address;
00323 #if HAVE_UPNP || HAVE_SOFIA_STUN
00324 int try_stun;
00325 #endif
00326 #if HAVE_UPNP
00327 #endif
00328 #if HAVE_SOFIA_STUN
00329 tport_master_t *tport;
00330 char *stun_server;
00331
00332 stun_handle_t *stun;
00333 su_socket_t stun_socket;
00334 su_sockaddr_t sockaddr;
00335 #endif
00336 } mr_nat[1];
00337 #endif
00338 };
00339
00341 struct tport_vtable
00342 {
00343 char const *vtp_name;
00344 enum tport_via vtp_public;
00345
00346 size_t vtp_pri_size;
00347 int (*vtp_init_primary)(tport_primary_t *pri,
00348 tp_name_t tpn[1],
00349 su_addrinfo_t *ai, tagi_t const *,
00350 char const **return_culprit);
00351 void (*vtp_deinit_primary)(tport_primary_t *pri);
00352 int (*vtp_wakeup_pri)(tport_primary_t *pri, int events);
00353 tport_t *(*vtp_connect)(tport_primary_t *pri, su_addrinfo_t *ai,
00354 tp_name_t const *tpn);
00355
00356 size_t vtp_secondary_size;
00357
00358 int (*vtp_init_secondary)(tport_t *, int socket, int accepted,
00359 char const **return_reason);
00360 void (*vtp_deinit_secondary)(tport_t *);
00361 void (*vtp_shutdown)(tport_t *, int how);
00362 int (*vtp_set_events)(tport_t const *self);
00363 int (*vtp_wakeup)(tport_t *self, int events);
00364 int (*vtp_recv)(tport_t *self);
00365 ssize_t (*vtp_send)(tport_t const *self, msg_t *msg,
00366 msg_iovec_t iov[], size_t iovused);
00367 void (*vtp_deliver)(tport_t *self, msg_t *msg, su_time_t now);
00368 int (*vtp_prepare)(tport_t *self, msg_t *msg,
00369 tp_name_t const *tpn,
00370 struct sigcomp_compartment *cc,
00371 unsigned mtu);
00372 int (*vtp_keepalive)(tport_t *self, su_addrinfo_t const *ai,
00373 tagi_t const *taglist);
00374 int (*vtp_stun_response)(tport_t const *self,
00375 void *msg, size_t msglen,
00376 void *addr, socklen_t addrlen);
00377 int (*vtp_next_secondary_timer)(tport_t *self, su_time_t *,
00378 char const **return_why);
00379 void (*vtp_secondary_timer)(tport_t *self, su_time_t);
00380 };
00381
00382 int tport_register_type(tport_vtable_t const *vtp);
00383
00385 su_inline int tport_is_connection_oriented(tport_t const *self)
00386 {
00387 return self->tp_conn_orient;
00388 }
00389
00391 su_inline int tport_has_connection(tport_t const *self)
00392 {
00393 return self->tp_has_connection;
00394 }
00395
00396 void tport_has_been_updated(tport_t *tport);
00397
00398 int tport_primary_compression(tport_primary_t *pri,
00399 char const *compression,
00400 tagi_t const *tl);
00401
00402 void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos);
00403
00404 tport_t *tport_base_connect(tport_primary_t *pri,
00405 su_addrinfo_t *ai,
00406 su_addrinfo_t *name,
00407 tp_name_t const *tpn);
00408
00409 int tport_stream_init_primary(tport_primary_t *pri,
00410 su_socket_t socket,
00411 tp_name_t tpn[1],
00412 su_addrinfo_t *ai,
00413 tagi_t const *tags,
00414 char const **return_reason);
00415
00416 tport_t *tport_alloc_secondary(tport_primary_t *pri,
00417 int socket,
00418 int accepted,
00419 char const **return_reason);
00420
00421 int tport_accept(tport_primary_t *pri, int events);
00422 int tport_register_secondary(tport_t *self, su_wakeup_f wakeup, int events);
00423 void tport_zap_secondary(tport_t *self);
00424
00425 int tport_set_secondary_timer(tport_t *self);
00426 void tport_base_timer(tport_t *self, su_time_t now);
00427
00428 int tport_bind_socket(int socket,
00429 su_addrinfo_t *ai,
00430 char const **return_culprit);
00431 void tport_close(tport_t *self);
00432 int tport_shutdown0(tport_t *self, int how);
00433
00434 int tport_has_queued(tport_t const *self);
00435
00436 int tport_error_event(tport_t *self);
00437 void tport_recv_event(tport_t *self);
00438 void tport_send_event(tport_t *self);
00439 void tport_hup_event(tport_t *self);
00440 int tport_setname(tport_t *, char const *, su_addrinfo_t const *, char const *);
00441
00442 int tport_wakeup(su_root_magic_t *magic, su_wait_t *w, tport_t *self);
00443
00444 ssize_t tport_recv_iovec(tport_t const *self,
00445 msg_t **mmsg,
00446 msg_iovec_t iovec[msg_n_fragments], size_t N,
00447 int exact);
00448
00449 msg_t *tport_msg_alloc(tport_t const *self, usize_t size);
00450
00451 int tport_prepare_and_send(tport_t *self, msg_t *msg,
00452 tp_name_t const *tpn,
00453 struct sigcomp_compartment *cc,
00454 unsigned mtu);
00455 int tport_send_msg(tport_t *self, msg_t *msg,
00456 tp_name_t const *tpn,
00457 struct sigcomp_compartment *cc);
00458
00459 void tport_send_queue(tport_t *self);
00460
00461 void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
00462 tport_compressor_t *comp,
00463 su_time_t now);
00464 void tport_base_deliver(tport_t *self, msg_t *msg, su_time_t now);
00465
00466 int tport_recv_error_report(tport_t *self);
00467 void tport_error_report(tport_t *self, int errcode,
00468 su_sockaddr_t const *addr);
00469
00470 int tport_open_log(tport_master_t *mr, tagi_t *tags);
00471 void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
00472 char const *via, su_time_t now);
00473 void tport_dump_iovec(tport_t const *self, msg_t *msg,
00474 size_t n, su_iovec_t const iov[], size_t iovused,
00475 char const *what, char const *how);
00476
00477 int tport_tcp_ping(tport_t *self, su_time_t now);
00478 int tport_tcp_pong(tport_t *self);
00479
00480 extern tport_vtable_t const tport_udp_vtable;
00481 extern tport_vtable_t const tport_udp_client_vtable;
00482
00483 int tport_udp_init_primary(tport_primary_t *,
00484 tp_name_t tpn[1],
00485 su_addrinfo_t *,
00486 tagi_t const *,
00487 char const **return_culprit);
00488 void tport_udp_deinit_primary(tport_primary_t *);
00489 int tport_recv_dgram(tport_t *self);
00490 ssize_t tport_send_dgram(tport_t const *self, msg_t *msg,
00491 msg_iovec_t iov[], size_t iovused);
00492 int tport_udp_error(tport_t const *self, su_sockaddr_t name[1]);
00493
00494 extern tport_vtable_t const tport_tcp_vtable;
00495 extern tport_vtable_t const tport_tcp_client_vtable;
00496
00497 int tport_tcp_init_primary(tport_primary_t *,
00498 tp_name_t tpn[1],
00499 su_addrinfo_t *, tagi_t const *,
00500 char const **return_culprit);
00501 int tport_tcp_init_client(tport_primary_t *,
00502 tp_name_t tpn[1],
00503 su_addrinfo_t *, tagi_t const *,
00504 char const **return_culprit);
00505 int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
00506 char const **return_reason);
00507 int tport_recv_stream(tport_t *self);
00508 ssize_t tport_send_stream(tport_t const *self, msg_t *msg,
00509 msg_iovec_t iov[], size_t iovused);
00510
00511 int tport_tcp_next_timer(tport_t *self, su_time_t *, char const **);
00512 void tport_tcp_timer(tport_t *self, su_time_t);
00513
00514 int tport_next_recv_timeout(tport_t *, su_time_t *, char const **);
00515 void tport_recv_timeout_timer(tport_t *self, su_time_t now);
00516
00517 int tport_next_keepalive(tport_t *self, su_time_t *, char const **);
00518 void tport_keepalive_timer(tport_t *self, su_time_t now);
00519
00520 extern tport_vtable_t const tport_sctp_vtable;
00521 extern tport_vtable_t const tport_sctp_client_vtable;
00522 extern tport_vtable_t const tport_tls_vtable;
00523 extern tport_vtable_t const tport_tls_client_vtable;
00524 extern tport_vtable_t const tport_stun_vtable;
00525 extern tport_vtable_t const tport_http_connect_vtable;
00526 extern tport_vtable_t const tport_threadpool_vtable;
00527
00528 typedef struct tport_descriptor_s {
00529 char const *tpd_name;
00530 tport_vtable_t *tpd_vtable;
00531 su_addrinfo_t *tpd_hints;
00532 int tpd_is_client_only;
00533 } tport_descriptor_t;
00534
00535 typedef int const *(tport_set_f)(tport_master_t *mr,
00536 tp_name_t const *tpn,
00537 tagi_t const *taglist,
00538 tport_descriptor_t **return_set,
00539 int return_set_size);
00540
00541
00542
00543 int tport_init_stun_server(tport_master_t *mr, tagi_t const *tags);
00544 void tport_deinit_stun_server(tport_master_t *mr);
00545 int tport_recv_stun_dgram(tport_t const *self, msg_t **in_out_msg,
00546 su_sockaddr_t *from, socklen_t fromlen);
00547
00548 int tport_stun_server_add_socket(tport_t *tp);
00549 int tport_stun_server_remove_socket(tport_t *tp);
00550
00551 void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
00552 void tport_recv_message(tport_t *self, msg_t *msg, int error);
00553
00554 void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
00555 void tport_sent_message(tport_t *self, msg_t *msg, int error);
00556
00557
00558
00559 extern tport_comp_vtable_t const *tport_comp_vtable;
00560
00561 char const *tport_canonize_comp(char const *comp);
00562
00563 int tport_init_compressor(tport_t *,
00564 char const *comp_name,
00565 tagi_t const *tags);
00566 void tport_deinit_compressor(tport_t *);
00567
00568 struct sigcomp_compartment *
00569 tport_sigcomp_assign_if_needed(tport_t *self,
00570 struct sigcomp_compartment *cc);
00571
00572 struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self);
00573
00574 void tport_sigcomp_accept_incomplete(tport_t *self, msg_t *msg);
00575
00576 int tport_recv_comp_dgram(tport_t const *self,
00577 tport_compressor_t *sc,
00578 msg_t **in_out_msg,
00579 su_sockaddr_t *from,
00580 socklen_t fromlen);
00581
00582 ssize_t tport_send_comp(tport_t const *self,
00583 msg_t *msg,
00584 msg_iovec_t iov[],
00585 size_t iovused,
00586 struct sigcomp_compartment *cc,
00587 tport_compressor_t *sc);
00588
00589 SOFIA_END_DECLS
00590
00591 #endif