📄 sip_transport.h
字号:
/* $Id: sip_transport.h 974 2007-02-19 01:13:53Z bennylp $ *//* * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef __PJSIP_SIP_TRANSPORT_H__#define __PJSIP_SIP_TRANSPORT_H__/** * @file sip_transport.h * @brief SIP Transport */#include <pjsip/sip_msg.h>#include <pjsip/sip_parser.h>#include <pj/sock.h>#include <pj/list.h>#include <pj/ioqueue.h>#include <pj/timer.h>PJ_BEGIN_DECL/** * @defgroup PJSIP_TRANSPORT Transport * @ingroup PJSIP_CORE * @brief This is the transport framework. * * The transport framework is fully extensible. Please see * <A HREF="/docs.htm">PJSIP Developer's Guide</A> PDF * document for more information. * * Application MUST register at least one transport to PJSIP before any * messages can be sent or received. Please see @ref PJSIP_TRANSPORT_UDP * on how to create/register UDP transport to the transport framework. * * @{ *//***************************************************************************** * * GENERAL TRANSPORT (NAMES, TYPES, ETC.) * *****************************************************************************//* * Forward declaration for transport factory (since it is referenced by * the transport factory itself). */typedef struct pjsip_tpfactory pjsip_tpfactory;/** * Flags for SIP transports. */enum pjsip_transport_flags_e{ PJSIP_TRANSPORT_RELIABLE = 1, /**< Transport is reliable. */ PJSIP_TRANSPORT_SECURE = 2, /**< Transport is secure. */ PJSIP_TRANSPORT_DATAGRAM = 4 /**< Datagram based transport. (it's also assumed to be connectionless) */};/** * Check if transport tp is reliable. */#define PJSIP_TRANSPORT_IS_RELIABLE(tp) \ ((tp)->flag & PJSIP_TRANSPORT_RELIABLE)/** * Check if transport tp is secure. */#define PJSIP_TRANSPORT_IS_SECURE(tp) \ ((tp)->flag & PJSIP_TRANSPORT_SECURE)/** * Register new transport type to PJSIP. The PJSIP transport framework * contains the info for some standard transports, as declared by * #pjsip_transport_type_e. Application may use non-standard transport * with PJSIP, but before it does so, it must register the information * about the new transport type to PJSIP by calling this function. * * @param tp_flag The flags describing characteristics of this * transport type. * @param tp_name Transport type name. * @param def_port Default port to be used for the transport. * @param p_tp_type On successful registration, it will be filled with * the registered type. This argument is optional. * * @return PJ_SUCCESS if registration is successful, or * PJSIP_ETYPEEXISTS if the same transport type has * already been registered. */PJ_DECL(pj_status_t) pjsip_transport_register_type(unsigned tp_flag, const char *tp_name, int def_port, int *p_tp_type);/** * Get the transport type from the transport name. * * @param name Transport name, such as "TCP", or "UDP". * * @return The transport type, or PJSIP_TRANSPORT_UNSPECIFIED if * the name is not recognized as the name of supported * transport. */PJ_DECL(pjsip_transport_type_e) pjsip_transport_get_type_from_name(const pj_str_t *name);/** * Get the transport type for the specified flags. * * @param flag The transport flag. * * @return Transport type. */PJ_DECL(pjsip_transport_type_e) pjsip_transport_get_type_from_flag(unsigned flag);/** * Get transport flag from type. * * @param type Transport type. * * @return Transport flags. */PJ_DECL(unsigned)pjsip_transport_get_flag_from_type( pjsip_transport_type_e type );/** * Get the default SIP port number for the specified type. * * @param type Transport type. * * @return The port number, which is the default SIP port number for * the specified type. */PJ_DECL(int) pjsip_transport_get_default_port_for_type(pjsip_transport_type_e type);/** * Get transport type name. * * @param t Transport type. * * @return Transport name. */PJ_DECL(const char*) pjsip_transport_get_type_name(pjsip_transport_type_e t);/***************************************************************************** * * TRANSPORT SELECTOR. * *****************************************************************************//** * This structure describes the type of data in pjsip_tpselector. */typedef enum pjsip_tpselector_type{ /** Transport is not specified. */ PJSIP_TPSELECTOR_NONE, /** Use the specific transport to send request. */ PJSIP_TPSELECTOR_TRANSPORT, /** Use the specific listener to send request. */ PJSIP_TPSELECTOR_LISTENER,} pjsip_tpselector_type;/** * This structure describes the transport/listener preference to be used * when sending outgoing requests. * * Normally transport will be selected automatically according to rules about * sending requests. But some applications (such as proxies or B2BUAs) may * want to explicitly use specific transport to send requests, for example * when they want to make sure that outgoing request should go from a specific * network interface. * * The pjsip_tpselector structure is used for that purpose, i.e. to allow * application specificly request that a particular transport/listener * should be used to send request. This structure is used when calling * pjsip_tsx_set_transport() and pjsip_dlg_set_transport(). */typedef struct pjsip_tpselector{ /** The type of data in the union */ pjsip_tpselector_type type; /** Union representing the transport/listener criteria to be used. */ union { pjsip_transport *transport; pjsip_tpfactory *listener; void *ptr; } u;} pjsip_tpselector;/** * Add transport/listener reference in the selector to prevent the specified * transport/listener from being destroyed while application still has * reference to it. * * @param sel The transport selector. */PJ_DECL(void) pjsip_tpselector_add_ref(pjsip_tpselector *sel);/** * Decrement transport/listener reference in the selector. * @param sel The transport selector */PJ_DECL(void) pjsip_tpselector_dec_ref(pjsip_tpselector *sel);/***************************************************************************** * * RECEIVE DATA BUFFER. * *****************************************************************************//** * A customized ioqueue async operation key which is used by transport * to locate rdata when a pending read operation completes. */typedef struct pjsip_rx_data_op_key{ pj_ioqueue_op_key_t op_key; /**< ioqueue op_key. */ pjsip_rx_data *rdata; /**< rdata associated with this */} pjsip_rx_data_op_key;/** * Incoming message buffer. * This structure keep all the information regarding the received message. This * buffer lifetime is only very short, normally after the transaction has been * called, this buffer will be deleted/recycled. So care must be taken when * allocating storage from the pool of this buffer. */struct pjsip_rx_data{ /** * tp_info is part of rdata that remains static for the duration of the * buffer. It is initialized when the buffer was created by transport. */ struct { /** Memory pool for this buffer. */ pj_pool_t *pool; /** The transport object which received this packet. */ pjsip_transport *transport; /** Other transport specific data to be attached to this buffer. */ void *tp_data; /** Ioqueue key. */ pjsip_rx_data_op_key op_key; } tp_info; /** * pkt_info is initialized by transport when it receives an incoming * packet. */ struct { /** Time when the message was received. */ pj_time_val timestamp; /** Pointer to the original packet. */ char packet[PJSIP_MAX_PKT_LEN]; /** Zero termination for the packet. */ pj_uint32_t zero; /** The length of the packet received. */ pj_ssize_t len; /** The source address from which the packet was received. */ pj_sockaddr src_addr; /** The length of the source address. */ int src_addr_len; /** The IP source address string (NULL terminated). */ char src_name[16]; /** The IP source port number. */ int src_port; } pkt_info; /** * msg_info is initialized by transport mgr (tpmgr) before this buffer * is passed to endpoint. */ struct { /** Start of msg buffer. */ char *msg_buf; /** Length fo message. */ int len; /** The parsed message, if any. */ pjsip_msg *msg; /** Short description about the message. * Application should use #pjsip_rx_data_get_info() instead. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -