Loading...
Searching...
No Matches
tport_internal.h
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef TPORT_INTERNAL_H
#define TPORT_INTERNAL_H
#ifndef SU_H
#include <sofia-sip/su.h>
#endif
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/su_strlst.h>
#ifndef MSG_ADDR_H
#include <sofia-sip/msg_addr.h>
#endif
#ifndef TPORT_H
#include <sofia-sip/tport.h>
#endif
#if HAVE_SOFIA_STUN
#include "sofia-sip/stun.h"
#include "sofia-sip/stun_tag.h"
#endif
#include <sofia-sip/tport_plugins.h>
#ifndef SU_DEBUG
#define SU_DEBUG 3
#endif
#define SU_LOG tport_log
#include <sofia-sip/su_debug.h>
#if !defined(MSG_NOSIGNAL) || defined(__CYGWIN__) || defined(SYMBIAN)
#undef MSG_NOSIGNAL
#define MSG_NOSIGNAL (0)
#endif
#if (_WIN32_WINNT >= 0x0600)
#ifndef HAVE_MSG_TRUNC
#define HAVE_MSG_TRUNC 1
#endif
#endif
#if !HAVE_MSG_TRUNC
#define MSG_TRUNC (0)
#endif
#ifndef NONE
#define NONE ((void *)(intptr_t)-1)
#endif
SOFIA_BEGIN_DECLS
typedef struct tport_master tport_master_t;
typedef struct tport_pending_s tport_pending_t;
typedef struct tport_primary tport_primary_t;
typedef struct tport_vtable tport_vtable_t;
struct sigcomp_state_handler;
struct sigcomp_algorithm;
struct sigcomp_udvm;
struct sigcomp_magic;
struct sigcomp_compartment;
typedef long unsigned LU; /* for printf() and friends */
typedef struct {
unsigned tpp_mtu;
unsigned tpp_idle;
unsigned tpp_timeout;
unsigned tpp_keepalive;
unsigned tpp_pingpong;
unsigned tpp_sigcomp_lifetime;
unsigned tpp_thrpsize;
unsigned tpp_thrprqsize;
unsigned tpp_qsize;
unsigned tpp_drop;
int tpp_tos;
unsigned tpp_conn_orient:1;
unsigned tpp_sdwn_error:1;
unsigned tpp_stun_server:1;
unsigned tpp_pong2ping:1;
unsigned :0;
} tport_params_t;
struct tport_s {
su_home_t tp_home[1];
unsigned tp_accepted:1;
unsigned tp_conn_orient:1;
unsigned tp_has_connection:1;
unsigned tp_reusable:1;
unsigned tp_closed : 1;
unsigned tp_recv_close:2;
unsigned tp_send_close:2;
unsigned tp_has_keepalive:1;
unsigned tp_has_stun_server:1;
unsigned tp_trunc:1;
unsigned tp_is_connected:1;
unsigned tp_verified:1;
unsigned tp_error_reported:1;
/* Red-black tree */
unsigned tp_black:1;
unsigned:0;
tport_t *tp_left, *tp_right, *tp_dad;
tport_master_t *tp_master;
tport_primary_t *tp_pri;
tport_params_t *tp_params;
tp_magic_t *tp_magic;
su_timer_t *tp_timer;
su_time_t tp_ktime;
su_time_t tp_ptime;
tp_name_t tp_name[1];
su_strlst_t *tp_subjects;
#define tp_protoname tp_name->tpn_proto
#define tp_canon tp_name->tpn_canon
#define tp_host tp_name->tpn_host
#define tp_port tp_name->tpn_port
#define tp_ident tp_name->tpn_ident
su_socket_t tp_socket;
int tp_index;
int tp_events;
su_addrinfo_t tp_addrinfo[1];
su_sockaddr_t tp_addr[1];
#define tp_addrlen tp_addrinfo->ai_addrlen
/* ==== Receive queue ================================================== */
msg_t *tp_msg;
msg_t const *tp_rlogged;
su_time_t tp_rtime;
unsigned short tp_ping;
/* ==== Pending messages =============================================== */
unsigned short tp_reported;
unsigned tp_plen;
unsigned tp_pused;
tport_pending_t *tp_pending;
tport_pending_t *tp_released;
/* ==== Send queue ===================================================== */
msg_t **tp_queue;
unsigned short tp_qhead;
msg_iovec_t *tp_unsent;
size_t tp_unsentlen;
msg_iovec_t *tp_iov;
size_t tp_iovlen;
msg_t const *tp_slogged;
su_time_t tp_stime;
/* ==== Extensions ===================================================== */
tport_compressor_t *tp_comp;
/* ==== Statistics ===================================================== */
struct {
uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
} tp_stats;
};
struct tport_primary {
tport_t pri_primary[1];
#if DOXYGEN_ONLY
su_home_t pri_home[1];
#else
#define pri_home pri_primary->tp_home
#define pri_master pri_primary->tp_master
#define pri_protoname pri_primary->tp_name->tpn_proto
#endif
tport_vtable_t const
*pri_vtable;
int pri_public;
tport_primary_t *pri_next;
tport_t *pri_open;
tport_t *pri_closed;
unsigned pri_updating:1;
unsigned pri_natted:1;
unsigned pri_has_tls:1;
unsigned:0;
void *pri_stun_handle;
tport_params_t pri_params[1];
};
struct tport_master {
tport_t mr_master[1];
#if DOXYGEN_ONLY
su_home_t mr_home[1];
#else
#define mr_home mr_master->tp_home
#endif
int mr_stun_step_ready;
tp_stack_t *mr_stack;
tp_stack_class_t
const *mr_tpac;
int mr_log;
su_root_t *mr_root;
su_timer_t *mr_timer;
FILE *mr_dump_file;
char *mr_dump;
tport_primary_t *mr_primaries;
tport_params_t mr_params[1];
unsigned mr_boundserver:1;
unsigned mr_bindv6only:1;
unsigned :0;
/* Delivery context */
struct tport_delivery {
tport_t *d_tport;
msg_t *d_msg;
tp_name_t d_from[1];
tport_compressor_t *d_comp;
} mr_delivery[1];
tport_stun_server_t *mr_stun_server;
#if 0
struct tport_nat_s {
int initialized;
int bound;
int stun_enabled;
char *external_ip_address;
#if HAVE_UPNP || HAVE_SOFIA_STUN
int try_stun;
#endif
#if HAVE_UPNP
#endif
#if HAVE_SOFIA_STUN
tport_master_t *tport;
char *stun_server;
/* stun_socket_t *stun_socket; */
stun_handle_t *stun;
su_socket_t stun_socket;
su_sockaddr_t sockaddr;
#endif
} mr_nat[1];
#endif
};
struct tport_vtable
{
char const *vtp_name;
enum tport_via vtp_public;
size_t vtp_pri_size; /* Size of primary tport */
int (*vtp_init_primary)(tport_primary_t *pri,
tp_name_t tpn[1],
su_addrinfo_t *ai, tagi_t const *,
char const **return_culprit);
void (*vtp_deinit_primary)(tport_primary_t *pri);
int (*vtp_wakeup_pri)(tport_primary_t *pri, int events);
tport_t *(*vtp_connect)(tport_primary_t *pri, su_addrinfo_t *ai,
tp_name_t const *tpn);
size_t vtp_secondary_size; /* Size of secondary tport */
int (*vtp_init_secondary)(tport_t *, int socket, int accepted,
char const **return_reason);
void (*vtp_deinit_secondary)(tport_t *);
void (*vtp_shutdown)(tport_t *, int how);
int (*vtp_set_events)(tport_t const *self);
int (*vtp_wakeup)(tport_t *self, int events);
int (*vtp_recv)(tport_t *self);
ssize_t (*vtp_send)(tport_t const *self, msg_t *msg,
msg_iovec_t iov[], size_t iovused);
void (*vtp_deliver)(tport_t *self, msg_t *msg, su_time_t now);
int (*vtp_prepare)(tport_t *self, msg_t *msg,
tp_name_t const *tpn,
struct sigcomp_compartment *cc,
unsigned mtu);
int (*vtp_keepalive)(tport_t *self, su_addrinfo_t const *ai,
tagi_t const *taglist);
int (*vtp_stun_response)(tport_t const *self,
void *msg, size_t msglen,
void *addr, socklen_t addrlen);
int (*vtp_next_secondary_timer)(tport_t *self, su_time_t *,
char const **return_why);
void (*vtp_secondary_timer)(tport_t *self, su_time_t);
};
int tport_register_type(tport_vtable_t const *vtp);
su_inline int tport_is_connection_oriented(tport_t const *self)
{
return self->tp_conn_orient;
}
su_inline int tport_has_connection(tport_t const *self)
{
return self->tp_has_connection;
}
void tport_has_been_updated(tport_t *tport);
int tport_primary_compression(tport_primary_t *pri,
char const *compression,
tagi_t const *tl);
void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos);
tport_t *tport_base_connect(tport_primary_t *pri,
su_addrinfo_t *ai,
su_addrinfo_t *name,
tp_name_t const *tpn);
int tport_stream_init_primary(tport_primary_t *pri,
su_socket_t socket,
tp_name_t tpn[1],
su_addrinfo_t *ai,
tagi_t const *tags,
char const **return_reason);
tport_t *tport_alloc_secondary(tport_primary_t *pri,
int socket,
int accepted,
char const **return_reason);
int tport_accept(tport_primary_t *pri, int events);
int tport_register_secondary(tport_t *self, su_wakeup_f wakeup, int events);
void tport_zap_secondary(tport_t *self);
int tport_set_secondary_timer(tport_t *self);
void tport_base_timer(tport_t *self, su_time_t now);
int tport_bind_socket(int socket,
su_addrinfo_t *ai,
char const **return_culprit);
void tport_close(tport_t *self);
int tport_shutdown0(tport_t *self, int how);
int tport_has_queued(tport_t const *self);
int tport_error_event(tport_t *self);
void tport_recv_event(tport_t *self);
void tport_send_event(tport_t *self);
void tport_hup_event(tport_t *self);
int tport_setname(tport_t *, char const *, su_addrinfo_t const *, char const *);
int tport_wakeup(su_root_magic_t *magic, su_wait_t *w, tport_t *self);
ssize_t tport_recv_iovec(tport_t const *self,
msg_t **mmsg,
msg_iovec_t iovec[msg_n_fragments], size_t N,
int exact);
msg_t *tport_msg_alloc(tport_t const *self, usize_t size);
int tport_prepare_and_send(tport_t *self, msg_t *msg,
tp_name_t const *tpn,
struct sigcomp_compartment *cc,
unsigned mtu);
int tport_send_msg(tport_t *self, msg_t *msg,
tp_name_t const *tpn,
struct sigcomp_compartment *cc);
void tport_send_queue(tport_t *self);
void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
tport_compressor_t *comp,
su_time_t now);
void tport_base_deliver(tport_t *self, msg_t *msg, su_time_t now);
int tport_recv_error_report(tport_t *self);
void tport_error_report(tport_t *self, int errcode,
su_sockaddr_t const *addr);
int tport_open_log(tport_master_t *mr, tagi_t *tags);
void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
char const *via, su_time_t now);
void tport_dump_iovec(tport_t const *self, msg_t *msg,
size_t n, su_iovec_t const iov[], size_t iovused,
char const *what, char const *how);
int tport_tcp_ping(tport_t *self, su_time_t now);
int tport_tcp_pong(tport_t *self);
extern tport_vtable_t const tport_udp_vtable;
extern tport_vtable_t const tport_udp_client_vtable;
int tport_udp_init_primary(tport_primary_t *,
tp_name_t tpn[1],
su_addrinfo_t *,
tagi_t const *,
char const **return_culprit);
void tport_udp_deinit_primary(tport_primary_t *);
int tport_recv_dgram(tport_t *self);
ssize_t tport_send_dgram(tport_t const *self, msg_t *msg,
msg_iovec_t iov[], size_t iovused);
int tport_udp_error(tport_t const *self, su_sockaddr_t name[1]);
extern tport_vtable_t const tport_tcp_vtable;
extern tport_vtable_t const tport_tcp_client_vtable;
int tport_tcp_init_primary(tport_primary_t *,
tp_name_t tpn[1],
su_addrinfo_t *, tagi_t const *,
char const **return_culprit);
int tport_tcp_init_client(tport_primary_t *,
tp_name_t tpn[1],
su_addrinfo_t *, tagi_t const *,
char const **return_culprit);
int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
char const **return_reason);
int tport_recv_stream(tport_t *self);
ssize_t tport_send_stream(tport_t const *self, msg_t *msg,
msg_iovec_t iov[], size_t iovused);
int tport_tcp_next_timer(tport_t *self, su_time_t *, char const **);
void tport_tcp_timer(tport_t *self, su_time_t);
int tport_next_recv_timeout(tport_t *, su_time_t *, char const **);
void tport_recv_timeout_timer(tport_t *self, su_time_t now);
int tport_next_keepalive(tport_t *self, su_time_t *, char const **);
void tport_keepalive_timer(tport_t *self, su_time_t now);
extern tport_vtable_t const tport_sctp_vtable;
extern tport_vtable_t const tport_sctp_client_vtable;
extern tport_vtable_t const tport_tls_vtable;
extern tport_vtable_t const tport_tls_client_vtable;
extern tport_vtable_t const tport_stun_vtable;
extern tport_vtable_t const tport_http_connect_vtable;
extern tport_vtable_t const tport_threadpool_vtable;
typedef struct tport_descriptor_s {
char const *tpd_name;
tport_vtable_t *tpd_vtable;
su_addrinfo_t *tpd_hints;
int tpd_is_client_only;
} tport_descriptor_t;
typedef int const *(tport_set_f)(tport_master_t *mr,
tp_name_t const *tpn,
tagi_t const *taglist,
tport_descriptor_t **return_set,
int return_set_size);
/* STUN plugin */
int tport_init_stun_server(tport_master_t *mr, tagi_t const *tags);
void tport_deinit_stun_server(tport_master_t *mr);
int tport_recv_stun_dgram(tport_t const *self, msg_t **in_out_msg,
su_sockaddr_t *from, socklen_t fromlen);
int tport_stun_server_add_socket(tport_t *tp);
int tport_stun_server_remove_socket(tport_t *tp);
void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
void tport_recv_message(tport_t *self, msg_t *msg, int error);
void tport_sent_bytes(tport_t *self, ssize_t bytes, ssize_t on_line);
void tport_sent_message(tport_t *self, msg_t *msg, int error);
/* ---------------------------------------------------------------------- */
/* Compressor plugin */
extern tport_comp_vtable_t const *tport_comp_vtable;
char const *tport_canonize_comp(char const *comp);
int tport_init_compressor(tport_t *,
char const *comp_name,
tagi_t const *tags);
void tport_deinit_compressor(tport_t *);
struct sigcomp_compartment *
tport_sigcomp_assign_if_needed(tport_t *self,
struct sigcomp_compartment *cc);
struct sigcomp_udvm **tport_get_udvm_slot(tport_t *self);
void tport_sigcomp_accept_incomplete(tport_t *self, msg_t *msg);
int tport_recv_comp_dgram(tport_t const *self,
tport_compressor_t *sc,
msg_t **in_out_msg,
su_sockaddr_t *from,
socklen_t fromlen);
ssize_t tport_send_comp(tport_t const *self,
msg_t *msg,
msg_iovec_t iov[],
size_t iovused,
struct sigcomp_compartment *cc,
tport_compressor_t *sc);
SOFIA_END_DECLS
#endif /* TPORT_INTERNAL_H */
msg_addr.h
msg_iovec_t
struct su_iovec_s msg_iovec_t
msg_n_fragments
msg_n_fragments
msg_t
struct msg_s msg_t
tagi_t
tp_name_t
Transport name.
Definition tport.h:156
su.h
su_socket_t
int su_socket_t
su_iovec_t
struct su_iovec_s su_iovec_t
su_addrinfo_t
struct addrinfo su_addrinfo_t
su_home_t
SU_HOME_T su_home_t
su_inline
#define su_inline
su_debug.h
su_strlst.h
su_time_t
struct su_time_s su_time_t
uint64_t
SU_U64_T uint64_t
su_uniqueid.h
su_root_t
struct su_root_t su_root_t
su_wakeup_f
int(* su_wakeup_f)(su_root_magic_t *, su_wait_t *, su_wakeup_arg_t *arg)
su_root_magic_t
SU_ROOT_MAGIC_T su_root_magic_t
su_wait_t
struct pollfd su_wait_t
su_timer_t
struct su_timer_s su_timer_t
tport.h
Transport interface.
tp_stack_t
TP_STACK_T tp_stack_t
Type of stack object.
Definition tport.h:71
tp_magic_t
TP_MAGIC_T tp_magic_t
Type of transport-protocol-specific context object.
Definition tport.h:78
tport_plugins.h
Transport plugin interface.
tport_stun_server_t
TPORT_STUN_SERVER_T tport_stun_server_t
Safe type for tport server object.
Definition tport_plugins.h:43
tport_via
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.