summaryrefslogtreecommitdiff
path: root/pjsip/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-18 22:43:42 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-18 22:43:42 +0000
commit9e1924d579a65c21db21e76d227582bb9474bb57 (patch)
treea6a4a50056d13a9256ebdaed79b34a0b58bbc314 /pjsip/include
parent4f18a7f712fdb4cfb90b2c0813b93c95927ccd75 (diff)
The BIG transport modifications
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@54 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/include')
-rw-r--r--pjsip/include/pjsip/sip_config.h9
-rw-r--r--pjsip/include/pjsip/sip_endpoint.h47
-rw-r--r--pjsip/include/pjsip/sip_errno.h21
-rw-r--r--pjsip/include/pjsip/sip_misc.h2
-rw-r--r--pjsip/include/pjsip/sip_private.h55
-rw-r--r--pjsip/include/pjsip/sip_transaction.h2
-rw-r--r--pjsip/include/pjsip/sip_transport.h645
-rw-r--r--pjsip/include/pjsip/sip_types.h6
8 files changed, 419 insertions, 368 deletions
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h
index 67c00551..5620c33b 100644
--- a/pjsip/include/pjsip/sip_config.h
+++ b/pjsip/include/pjsip/sip_config.h
@@ -63,6 +63,15 @@
#define PJSIP_POOL_LEN_DIALOG 1200
#define PJSIP_POOL_INC_DIALOG 512
+/* Transport manager hash table size (must be 2^n-1). */
+#define PJSIP_TPMGR_HTABLE_SIZE 31
+
+/* Transport idle timeout before it's destroyed. */
+#define PJSIP_TRANSPORT_IDLE_TIME 30
+
+/* Max entries to process in timer heap per poll. */
+#define PJSIP_MAX_TIMED_OUT_ENTRIES 10
+
/* Module related constants. */
#define PJSIP_MAX_MODULE 8
diff --git a/pjsip/include/pjsip/sip_endpoint.h b/pjsip/include/pjsip/sip_endpoint.h
index e92775cd..24eca24f 100644
--- a/pjsip/include/pjsip/sip_endpoint.h
+++ b/pjsip/include/pjsip/sip_endpoint.h
@@ -259,51 +259,10 @@ PJ_DECL(void) pjsip_endpt_resolve( pjsip_endpoint *endpt,
*
* @see pjsip_transport_get
*/
-PJ_DECL(void) pjsip_endpt_get_transport( pjsip_endpoint *endpt,
- pj_pool_t *pool,
- pjsip_transport_type_e type,
- const pj_sockaddr_in *remote,
- void *token,
- pjsip_transport_completion_callback *cb);
-
-/**
- * Create listener a new transport listener. A listener is transport object
- * that is capable of receiving SIP messages. For UDP listener, normally
- * application should use #pjsip_endpt_create_udp_listener instead if the
- * application has already created the socket.
- * This function, like all other endpoint functions, is thread safe.
- *
- * @param endpt The endpoint instance.
- * @param type Transport type (eg. UDP, TCP, etc.)
- * @param addr The bound address of the transport.
- * @param addr_name The address to be advertised in SIP messages. For example,
- * the bound address can be 0.0.0.0, but the advertised address
- * normally will be the IP address of the host.
- *
- * @return Zero if listener is created successfully.
- */
-PJ_DECL(pj_status_t) pjsip_endpt_create_listener( pjsip_endpoint *endpt,
+PJ_DECL(pj_status_t) pjsip_endpt_alloc_transport( pjsip_endpoint *endpt,
pjsip_transport_type_e type,
- pj_sockaddr_in *addr,
- const pj_sockaddr_in *addr_name);
-
-/**
- * Create UDP listener. For UDP, normally the application would create the
- * socket by itself (for STUN purpose), then it can register the socket as
- * listener by calling this function.
- * This function, like all other endpoint functions, is thread safe.
- *
- * @param endpt The endpoint instance.
- * @param sock The socket handle.
- * @param addr_name The address to be advertised in SIP message. If the socket
- * has been resolved with STUN, then application may specify
- * the mapped address in this parameter.
- *
- * @return Zero if listener is created successfully.
- */
-PJ_DECL(pj_status_t) pjsip_endpt_create_udp_listener( pjsip_endpoint *endpt,
- pj_sock_t sock,
- const pj_sockaddr_in *addr_name);
+ const pj_sockaddr_in *remote,
+ pjsip_transport **p_transport);
/**
* Get additional headers to be put in outgoing request message.
diff --git a/pjsip/include/pjsip/sip_errno.h b/pjsip/include/pjsip/sip_errno.h
index 1d777e42..5473f362 100644
--- a/pjsip/include/pjsip/sip_errno.h
+++ b/pjsip/include/pjsip/sip_errno.h
@@ -54,6 +54,11 @@
/**
* @hideinitializer
+ * Invalid message (syntax error)
+ */
+#define PJSIP_EINVALIDMSG (PJSIP_ERRNO_START_PJSIP + 0)
+/**
+ * @hideinitializer
* Missing required header(s).
*/
#define PJSIP_EMISSINGHDR (PJSIP_ERRNO_START_PJSIP + 1)
@@ -97,6 +102,22 @@
* Invalid Via header in response (sent-by, etc).
*/
#define PJSIP_EINVALIDVIA (PJSIP_ERRNO_START_PJSIP + 9)
+/**
+ * @hideinitializer
+ * Multiple Via headers in response.
+ */
+#define PJSIP_EMULTIPLEVIA (PJSIP_ERRNO_START_PJSIP + 9)
+/**
+ * @hideinitializer
+ * SIP object is busy.
+ */
+#define PJSIP_EBUSY (PJSIP_ERRNO_START_PJSIP + 10)
+/**
+ * @hideinitializer
+ * SIP object with the same type already exists.
+ */
+#define PJSIP_ETYPEEXISTS (PJSIP_ERRNO_START_PJSIP + 11)
+
#endif /* __PJSIP_SIP_ERRNO_H__ */
diff --git a/pjsip/include/pjsip/sip_misc.h b/pjsip/include/pjsip/sip_misc.h
index 0217e36e..f8685e54 100644
--- a/pjsip/include/pjsip/sip_misc.h
+++ b/pjsip/include/pjsip/sip_misc.h
@@ -178,7 +178,7 @@ PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt,
* @return zero (PJ_OK) if successfull.
*/
PJ_DECL(pj_status_t) pjsip_get_response_addr(pj_pool_t *pool,
- const pjsip_transport_t *tr,
+ const pjsip_transport *tr,
const pjsip_via_hdr *via,
pjsip_host_port *addr);
diff --git a/pjsip/include/pjsip/sip_private.h b/pjsip/include/pjsip/sip_private.h
index 9e2ccc9b..1c14e607 100644
--- a/pjsip/include/pjsip/sip_private.h
+++ b/pjsip/include/pjsip/sip_private.h
@@ -35,61 +35,6 @@ PJ_BEGIN_DECL
*/
-/**
- * Create a new transport manager.
- * @param pool The pool
- * @param endpt The endpoint
- * @param cb Callback to be called to receive messages from transport.
- */
-PJ_DECL(pj_status_t) pjsip_transport_mgr_create( pj_pool_t *pool,
- pjsip_endpoint *endpt,
- void (*cb)(pjsip_endpoint *,
- pjsip_rx_data *),
- pjsip_transport_mgr **);
-
-
-/**
- * Destroy transport manager and release all transports.
- * @param mgr Transport manager to be destroyed.
- */
-PJ_DECL(pj_status_t) pjsip_transport_mgr_destroy( pjsip_transport_mgr *mgr );
-
-/**
- * Poll for transport events.
- * Incoming messages will be parsed by the transport manager, and the callback
- * will be called for each of this message.
- * @param endpt The endpoint.
- * @param timeout Timeout value, or NULL to wait forever.
- */
-PJ_DECL(int) pjsip_transport_mgr_handle_events( pjsip_transport_mgr *mgr,
- const pj_time_val *timeout );
-
-/**
- * Get the pointer to the first transport iterator.
- * @param mgr The transport manager.
- * @param it The iterator used for iterating the hash element.
- * @return the iterator to the first transport, or NULL.
- */
-PJ_DECL(pj_hash_iterator_t*) pjsip_transport_first( pjsip_transport_mgr *mgr,
- pj_hash_iterator_t *it );
-
-
-/**
- * Get the next transport iterator.
- * @param itr the iterator to the transport.
- * @return the iterator pointed to the next transport, or NULL.
- */
-PJ_DECL(pj_hash_iterator_t*) pjsip_transport_next( pjsip_transport_mgr *mgr,
- pj_hash_iterator_t *itr );
-
-/**
- * Get the value of transport iterator.
- * @param mgr the transport manager.
- * @param itr the transport iterator.
- * @return the transport associated with the iterator.
- */
-PJ_DECL(pjsip_transport_t*) pjsip_transport_this( pjsip_transport_mgr *mgr,
- pj_hash_iterator_t *itr );
/**
* @}
diff --git a/pjsip/include/pjsip/sip_transaction.h b/pjsip/include/pjsip/sip_transaction.h
index 8a653222..4090ca4c 100644
--- a/pjsip/include/pjsip/sip_transaction.h
+++ b/pjsip/include/pjsip/sip_transaction.h
@@ -111,7 +111,7 @@ struct pjsip_transaction
pjsip_server_addresses remote_addr; /**< Addresses resolved. */
int current_addr; /**< Address currently used. */
- pjsip_transport_t *transport; /**< Transport to use. */
+ pjsip_transport *transport; /**< Transport to use. */
/*
* Messages and timer.
diff --git a/pjsip/include/pjsip/sip_transport.h b/pjsip/include/pjsip/sip_transport.h
index 950ee5cf..36cf863e 100644
--- a/pjsip/include/pjsip/sip_transport.h
+++ b/pjsip/include/pjsip/sip_transport.h
@@ -29,6 +29,7 @@
#include <pj/sock.h>
#include <pj/list.h>
#include <pj/ioqueue.h>
+#include <pj/timer.h>
PJ_BEGIN_DECL
@@ -43,6 +44,78 @@ PJ_BEGIN_DECL
* @{
*/
+/*****************************************************************************
+ *
+ * GENERAL TRANSPORT (NAMES, TYPES, ETC.)
+ *
+ *****************************************************************************/
+
+/**
+ * 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. */
+};
+
+/**
+ * Check if transport tp is reliable.
+ */
+#define PJSIP_TRANSPORT_IS_RELIABLE(tp) \
+ ((tp)->flag & PJSIP_TRANSPORT_RELIABLE)
+
+/**
+ * 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);
+
+
+/*****************************************************************************
+ *
+ * RECEIVE DATA BUFFER.
+ *
+ *****************************************************************************/
+
/**
* Incoming message buffer.
* This structure keep all the information regarding the received message. This
@@ -52,78 +125,130 @@ PJ_BEGIN_DECL
*/
struct pjsip_rx_data
{
- //PJ_DECL_LIST_MEMBER(struct pjsip_rx_data);
- /** Memory pool for this buffer. */
- pj_pool_t *pool;
+ /**
+ * 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;
- /** Ioqueue op key. */
- pj_ioqueue_op_key_t op_key;
+ /** The transport object which received this packet. */
+ pjsip_transport *transport;
+
+ /** Ioqueue key. */
+ pj_ioqueue_op_key_t op_key;
- /** Time when the message was received. */
- pj_time_val timestamp;
+ } tp_info;
- /** The packet buffer. */
- char packet[PJSIP_MAX_PKT_LEN];
- /** The length of the packet received. */
- int len;
+ /**
+ * 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 source address from which the packet was received. */
- pj_sockaddr_in addr;
+ /** The length of the packet received. */
+ int len;
- /** The length of the source address. */
- int addr_len;
+ /** The source address from which the packet was received. */
+ pj_sockaddr_in addr;
- /** The transport object which received this packet. */
- pjsip_transport_t *transport;
+ /** The length of the source address. */
+ int addr_len;
- /** The parsed message, if any. */
- pjsip_msg *msg;
+ } pkt_info;
- /** This the transaction key generated from the message. This key is only
- * available after the rdata has reached the endpoint.
+
+ /**
+ * msg_info is initialized by transport mgr (tpmgr) before this buffer
+ * is passed to endpoint.
*/
- pj_str_t key;
+ struct
+ {
+ /** Start of msg buffer. */
+ char *msg_buf;
+
+ /** Length fo message. */
+ int len;
+
+ /** The parsed message, if any. */
+ pjsip_msg *msg;
- /** The Call-ID header as found in the message. */
- pj_str_t call_id;
+ /** The Call-ID header as found in the message. */
+ pj_str_t call_id;
- /** The From header as found in the message. */
- pjsip_from_hdr *from;
+ /** The From header as found in the message. */
+ pjsip_from_hdr *from;
- /** The To header as found in the message. */
- pjsip_to_hdr *to;
+ /** The To header as found in the message. */
+ pjsip_to_hdr *to;
- /** The topmost Via header as found in the message. */
- pjsip_via_hdr *via;
+ /** The topmost Via header as found in the message. */
+ pjsip_via_hdr *via;
- /** The CSeq header as found in the message. */
- pjsip_cseq_hdr *cseq;
+ /** The CSeq header as found in the message. */
+ pjsip_cseq_hdr *cseq;
- /** Max forwards header. */
- pjsip_max_forwards_hdr *max_fwd;
+ /** Max forwards header. */
+ pjsip_max_forwards_hdr *max_fwd;
- /** The first route header. */
- pjsip_route_hdr *route;
+ /** The first route header. */
+ pjsip_route_hdr *route;
- /** The first record-route header. */
- pjsip_rr_hdr *record_route;
+ /** The first record-route header. */
+ pjsip_rr_hdr *record_route;
- /** Content-type header. */
- pjsip_ctype_hdr *ctype;
+ /** Content-type header. */
+ pjsip_ctype_hdr *ctype;
- /** Content-length header. */
- pjsip_clen_hdr *clen;
+ /** Content-length header. */
+ pjsip_clen_hdr *clen;
+
+ /** The first Require header. */
+ pjsip_require_hdr *require;
+
+ /** The list of error generated by the parser when parsing
+ this message.
+ */
+ pjsip_parser_err_report parse_err;
+
+ } msg_info;
+
+
+ /**
+ * endpt_info is initialized by endpoint after this buffer reaches
+ * endpoint.
+ */
+ struct
+ {
+ /**
+ * This the transaction key generated for the message.
+ */
+ pj_str_t key;
- /** The first Require header. */
- pjsip_require_hdr *require;
+ } endpt_info;
- /** The list of error generated by the parser when parsing this message. */
- pjsip_parser_err_report parse_err;
};
+/*****************************************************************************
+ *
+ * TRANSMIT DATA BUFFER MANIPULATION.
+ *
+ *****************************************************************************/
+
/**
* Data structure for sending outgoing message. Application normally creates
* this buffer by calling #pjsip_endpt_create_tdata.
@@ -156,11 +281,14 @@ struct pjsip_tx_data
pj_time_val rx_timestamp;
/** The transport manager for this buffer. */
- pjsip_transport_mgr *mgr;
+ pjsip_tpmgr *mgr;
/** Ioqueue asynchronous operation key. */
pj_ioqueue_op_key_t op_key;
+ /** Lock object. */
+ pj_lock_t *lock;
+
/** The message in this buffer. */
pjsip_msg *msg;
@@ -174,10 +302,31 @@ struct pjsip_tx_data
/** Reference counter. */
pj_atomic_t *ref_cnt;
+
+ /** Being sent? */
+ int is_pending;
+
+ /** Transport internal. */
+ void *token;
+ void (*cb)(void*, pjsip_tx_data*, pj_status_t);
};
/**
+ * Create a new, blank transmit buffer. The reference count is initialized
+ * to zero.
+ *
+ * @param mgr The transport manager.
+ * @param tdata Pointer to receive transmit data.
+ *
+ * @return PJ_SUCCESS, or the appropriate error code.
+ *
+ * @see pjsip_endpt_create_tdata
+ */
+pj_status_t pjsip_tx_data_create( pjsip_tpmgr *mgr,
+ pjsip_tx_data **tdata );
+
+/**
* Add reference counter to the transmit buffer. The reference counter controls
* the life time of the buffer, ie. when the counter reaches zero, then it
* will be destroyed.
@@ -195,6 +344,13 @@ PJ_DECL(void) pjsip_tx_data_add_ref( pjsip_tx_data *tdata );
PJ_DECL(void) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata );
/**
+ * Check if transmit data buffer contains a valid message.
+ *
+ * @param tdata The transmit buffer.
+ */
+PJ_DECL(pj_bool_t) pjsip_tx_data_is_valid( pjsip_tx_data *tdata );
+
+/**
* Invalidate the print buffer to force message to be re-printed. Call
* when the message has changed after it has been printed to buffer. The
* message is printed to buffer normally by transport when it is about to be
@@ -207,288 +363,251 @@ PJ_DECL(void) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata );
PJ_DECL(void) pjsip_tx_data_invalidate_msg( pjsip_tx_data *tdata );
-/**
- * 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_IOQUEUE_BUSY = 4, /**< WTH?? */
-};
-
-/**
- * Get the transport type from the transport name.
+/*****************************************************************************
*
- * @param name Transport name, such as "TCP", or "UDP".
+ * TRANSPORT
*
- * @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.
+ * This structure represent the "public" interface of a SIP transport.
+ * Applications normally extend this structure to include transport
+ * specific members.
*/
-PJ_DECL(pjsip_transport_type_e)
-pjsip_transport_get_type_from_flag(unsigned flag);
+typedef struct pjsip_transport
+{
+ char obj_name[PJ_MAX_OBJ_NAME]; /**< Name. */
+
+ pj_pool_t *pool; /**< Pool used by transport. */
+ pj_atomic_t *ref_cnt; /**< Reference counter. */
+ pj_lock_t *lock; /**< Lock object. */
+ int tracing; /**< Tracing enabled? */
+
+ pjsip_transport_type_e type; /**< Transport type. */
+ char type_name[8]; /**< Type name. */
+ unsigned flag; /**< #pjsip_transport_flags_e */
+
+ pj_sockaddr_in local_addr; /**< Bound address. */
+ pj_sockaddr_in public_addr; /**< STUN addres. */
+ pj_sockaddr_in rem_addr; /**< Remote addr (zero for UDP) */
+
+ pjsip_tpmgr *tpmgr; /**< Transport manager. */
+ pj_timer_entry idle_timer; /**< Timer when ref cnt is zero.*/
+
+ /**
+ * Function to be called by transport manager to send SIP message.
+ *
+ * @param transport The transport to send the message.
+ * @param packet The buffer to send.
+ * @param length The length of the buffer to send.
+ * @param op_key Completion token, which will be supplied to
+ * caller when pending send operation completes.
+ * @param rem_addr The remote destination address.
+ * @param callback If supplied, the callback will be called
+ * once a pending transmission has completed. If
+ * the function completes immediately (i.e. return
+ * code is not PJ_EPENDING), the callback will not
+ * be called.
+ *
+ * @return Should return PJ_SUCCESS only if data has been
+ * succesfully queued to operating system for
+ * transmission. Otherwise it may return PJ_EPENDING
+ * if the underlying transport can not send the
+ * data immediately and will send it later, which in
+ * this case caller doesn't have to do anything
+ * except wait the calback to be called, if it
+ * supplies one.
+ * Other return values indicate the error code.
+ */
+ pj_status_t (*send_msg)(pjsip_transport *transport,
+ const void *packet,
+ pj_size_t length,
+ pj_ioqueue_op_key_t *op_key,
+ const pj_sockaddr_in *rem_addr,
+ void *token,
+ void (*callback)(pjsip_transport *transport,
+ void *token,
+ pj_status_t status));
+
+ /**
+ * Destroy this transport.
+ */
+ pj_status_t (*destroy)(pjsip_transport *transport);
+
+ /*
+ * Application may extend this structure..
+ */
+} pjsip_transport;
+
/**
- * 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.
+ * Register a transport.
*/
-PJ_DECL(int)
-pjsip_transport_get_default_port_for_type(pjsip_transport_type_e type);
+PJ_DECL(pj_status_t) pjsip_transport_register( pjsip_tpmgr *mgr,
+ pjsip_transport *tp );
/**
- * Add reference to transport.
- * Transactions or dialogs that uses a particular transport must call this
- * function to indicate that the transport is being used, thus preventing the
- * transport from being closed.
- *
- * @param transport The transport.
+ * Unregister transport. This will eventually call the transport to
+ * destroy itself.
*/
-PJ_DECL(void)
-pjsip_transport_add_ref( pjsip_transport_t *transport );
+PJ_DECL(pj_status_t) pjsip_transport_unregister( pjsip_tpmgr *mgr,
+ pjsip_transport *tp);
/**
- * Decrease reference to transport.
- * When the transport reference counter becomes zero, a timer will be started
- * and when this timer expires and the reference counter is still zero, the
- * transport will be released.
- *
- * @param transport The transport
+ * Add ref.
*/
-PJ_DECL(void)
-pjsip_transport_dec_ref( pjsip_transport_t *transport );
-
+PJ_DECL(pj_status_t) pjsip_transport_add_ref( pjsip_transport *tp );
/**
- * Macro to check whether the transport is reliable.
- *
- * @param transport The transport
- *
- * @return non-zero (not necessarily 1) if transport is reliable.
+ * Dec ref.
*/
-#define PJSIP_TRANSPORT_IS_RELIABLE(transport) \
- (pjsip_transport_get_flag(transport) & PJSIP_TRANSPORT_RELIABLE)
+PJ_DECL(pj_status_t) pjsip_transport_dec_ref( pjsip_transport *tp );
/**
- * Macro to check whether the transport is secure.
- *
- * @param transport The transport
- *
- * @return non-zero (not necessarily one) if transport is secure.
+ * Call for incoming message.
*/
-#define PJSIP_TRANSPORT_IS_SECURE(transport) \
- (pjsip_transport_get_flag(transport) & PJSIP_TRANSPORT_SECURE)
+PJ_DECL(pj_ssize_t) pjsip_tpmgr_receive_packet(pjsip_tpmgr *mgr,
+ pjsip_rx_data *rdata);
-/**
- * Get the transport type.
+
+/*****************************************************************************
*
- * @param tr The transport.
+ * TRANSPORT FACTORY
*
- * @return Transport type.
- */
-PJ_DECL(pjsip_transport_type_e)
-pjsip_transport_get_type( const pjsip_transport_t * tr);
+ *****************************************************************************/
-/**
- * Get the transport type name (ie "UDP", or "TCP").
- *
- * @param tr The transport.
- * @return The string type.
- */
-PJ_DECL(const char *)
-pjsip_transport_get_type_name( const pjsip_transport_t * tr);
/**
- * Get the transport's object name.
- *
- * @param tr The transport.
- * @return The object name.
+ * Transport factory.
*/
-PJ_DECL(const char*)
-pjsip_transport_get_obj_name( const pjsip_transport_t *tr );
+typedef struct pjsip_tpfactory pjsip_tpfactory;
/**
- * Get the transport's reference counter.
- *
- * @param tr The transport.
- * @return The reference count value.
+ * Transport factory.
*/
-PJ_DECL(int)
-pjsip_transport_get_ref_cnt( const pjsip_transport_t *tr );
+struct pjsip_tpfactory
+{
+ /* This list is managed by transport manager. */
+ PJ_DECL_LIST_MEMBER(struct pjsip_tpfactory);
+
+ pj_pool_t *pool;
+ pj_lock_t *lock;
+
+ pjsip_transport_type_e type;
+ char type_name[8];
+ unsigned flag;
+
+ pj_sockaddr_in local_addr;
+ pj_sockaddr_in public_addr;
+
+ /**
+ * Create new outbound connection.
+ */
+ pj_status_t (*create_transport)(pjsip_tpfactory *factory,
+ pjsip_tpmgr *mgr,
+ pjsip_endpoint *endpt,
+ pj_ioqueue_t *ioqueue,
+ const pj_sockaddr_in *rem_addr,
+ pjsip_transport **transport);
+
+ /*
+ * Application may extend this structure..
+ */
+};
+
-/**
- * Get transport flag.
- *
- * @param tr The transport.
- * @return Transport flag.
- */
-PJ_DECL(unsigned)
-pjsip_transport_get_flag( const pjsip_transport_t * tr );
/**
- * Get the local address of the transport, ie. the address which the socket
- * is bound.
+ * Register a transport factory.
*
- * @param tr The transport.
- * @return The address.
+ * @param mgr The transport manager.
+ * @param factory Transport factory.
+ *
+ * @return PJ_SUCCESS if listener was successfully created.
*/
-PJ_DECL(const pj_sockaddr_in *)
-pjsip_transport_get_local_addr( pjsip_transport_t * tr );
+PJ_DECL(pj_status_t) pjsip_tpmgr_register_tpfactory(pjsip_tpmgr *mgr,
+ pjsip_tpfactory *tpf);
/**
- * Get the address name of the transport. Address name can be an arbitrary
- * address assigned to a transport. This is usefull for example when STUN
- * is used, then the address name of an UDP transport can specify the public
- * address of the transport. When the address name is not set, then value
- * will be equal to the local/bound address. Application should normally
- * prefer to use the address name instead of the local address.
- *
- * @param tr The transport.
- * @return The address name.
+ * Unregister factory.
*/
-PJ_DECL(const pj_sockaddr_in*)
-pjsip_transport_get_addr_name (pjsip_transport_t *tr);
+PJ_DECL(pj_status_t) pjsip_tpmgr_unregister_tpfactory(pjsip_tpmgr *mgr,
+ pjsip_tpfactory *tpf);
-/**
- * Get the remote address of the transport. Not all transports will have
- * a valid remote address. UDP transports, for example, will likely to have
- * zero has their remote address, because UDP transport can be used to send
- * and receive messages from multiple destinations.
+
+/*****************************************************************************
*
- * @param tr The transport.
- * @return The address.
- */
-PJ_DECL(const pj_sockaddr_in *)
-pjsip_transport_get_remote_addr( const pjsip_transport_t * tr );
+ * TRANSPORT MANAGER
+ *
+ *****************************************************************************/
/**
- * Send a SIP message using the specified transport, to the address specified
- * in the outgoing data. This function is only usefull for application when it
- * wants to handle the message statelessly, because otherwise it should create
- * a transaction and let the transaction handles the transmission of the
- * message.
- *
- * This function will send the message immediately, so application must be
- * sure that the transport is ready to do so before calling this function.
+ * Create a new transport manager.
*
- * @param tr The transport to send the message.
- * @param tdata The outgoing message buffer.
- * @param addr The remote address.
- * @param sent If not null, it will be filled up with the length of
- * data sent.
+ * @param pool Pool.
+ * @param endpt Endpoint instance.
+ * @param cb Callback to receive incoming message.
+ * @param p_mgr Pointer to receive the new transport manager.
*
- * @return PJ_SUCCESS on success, or the appropriate error code.
+ * @return PJ_SUCCESS or the appropriate error code on error.
*/
-PJ_DECL(pj_status_t) pjsip_transport_send_msg( pjsip_transport_t *tr,
- pjsip_tx_data *tdata,
- const pj_sockaddr_in *addr,
- pj_ssize_t *sent);
+PJ_DECL(pj_status_t) pjsip_tpmgr_create( pj_pool_t *pool,
+ pjsip_endpoint * endpt,
+ pj_ioqueue_t *ioqueue,
+ pj_timer_heap_t *timer_heap,
+ void (*cb)(pjsip_endpoint*,
+ pj_status_t,
+ pjsip_rx_data *),
+ pjsip_tpmgr **p_mgr);
/**
- * @}
+ * Destroy transport manager.
*/
+PJ_DECL(pj_status_t) pjsip_tpmgr_destroy(pjsip_tpmgr *mgr);
-/*
- * PRIVATE FUNCTIONS!!!
- *
- * These functions are normally to be used by endpoint. Application should
- * use the variant provided by the endpoint instance.
- *
- * Application normally wouldn't be able to call these functions because it
- * has no reference of the transport manager (the instance of the transport
- * manager is hidden by endpoint!).
- */
-/*
- * Create a new transmit buffer.
- *
- * @param mgr The transport manager.
- * @return The transmit buffer data, or NULL on error.
+/**
+ * Dump transport info.
*/
-pj_status_t pjsip_tx_data_create( pjsip_transport_mgr *mgr,
- pjsip_tx_data **tdata );
+PJ_DECL(void) pjsip_tpmgr_dump_transports(pjsip_tpmgr *mgr);
-/**
- * Create listener.
+/*****************************************************************************
*
- * @param mgr The transport manager.
- * @param type Transport type.
- * @param local_addr The address to bind.
- * @param addr_name If not null, sets the address name. If NULL,
- * then the local address will be used.
+ * PUBLIC API
*
- * @return PJ_SUCCESS if listener was successfully created.
- */
-PJ_DECL(pj_status_t) pjsip_create_listener( pjsip_transport_mgr *mgr,
- pjsip_transport_type_e type,
- pj_sockaddr_in *local_addr,
- const pj_sockaddr_in *addr_name);
+ *****************************************************************************/
/**
- * Create UDP listener.
- *
- * @param mgr The transport manager.
- * @param sock The UDP socket.
- * @param addr_name If not null, sets the address name. If NULL,
- * then the local address will be used.
- *
- * @return PJ_SUCCESS if listener was successfully created.
+ * Find transport to be used to send message to remote destination. If no
+ * suitable transport is found, a new one will be created.
*/
-PJ_DECL(pj_status_t) pjsip_create_udp_listener( pjsip_transport_mgr *mgr,
- pj_sock_t sock,
- const pj_sockaddr_in *addr_name);
+PJ_DECL(pj_status_t) pjsip_tpmgr_alloc_transport( pjsip_tpmgr *mgr,
+ pjsip_transport_type_e type,
+ const pj_sockaddr_in *remote,
+ pjsip_transport **p_transport );
-/**
- * Type of function to receive asynchronous transport completion for
- * pjsip_transport_get() operation.
- *
- * @param tr The transport.
- * @param token Token registered previously.
- * @param status Status of operation.
+
+/**
+ * Send a SIP message using the specified transport.
*/
-typedef void pjsip_transport_completion_callback(pjsip_transport_t *tr,
- void *token,
- pj_status_t status);
+PJ_DECL(pj_status_t) pjsip_transport_send( pjsip_transport *tr,
+ pjsip_tx_data *tdata,
+ const pj_sockaddr_in *addr,
+ void *token,
+ void (*cb)(void *token,
+ pjsip_tx_data *tdata,
+ pj_status_t));
+
/**
- * Find transport to be used to send message to remote destination. If no
- * suitable transport is found, a new one will be created. If transport
- * can not be available immediately (for example, an outgoing TCP connec()),
- * then the caller will be notified later via the callback.
- *
- * @param mgr The transport manager.
- * @param pool Pool to allocate asychronous job (if required).
- * @param type The transport type.
- * @param remote The remote address.
- * @param token The token that will be passed to the callback.
- * @param cb The callback to be called to report the completion of
- * the operation.
- */
-PJ_DECL(void) pjsip_transport_get( pjsip_transport_mgr *mgr,
- pj_pool_t *pool,
- pjsip_transport_type_e type,
- const pj_sockaddr_in *remote,
- void *token,
- pjsip_transport_completion_callback *cb);
+ * @}
+ */
+
PJ_END_DECL
diff --git a/pjsip/include/pjsip/sip_types.h b/pjsip/include/pjsip/sip_types.h
index 7ac2044e..6554b4ce 100644
--- a/pjsip/include/pjsip/sip_types.h
+++ b/pjsip/include/pjsip/sip_types.h
@@ -25,12 +25,12 @@
/**
* Opaque data structure for transports (sip_transport.h).
*/
-typedef struct pjsip_transport_t pjsip_transport_t;
+typedef struct pjsip_transport pjsip_transport;
/**
* Opaque data type for transport manager (sip_transport.h).
*/
-typedef struct pjsip_transport_mgr pjsip_transport_mgr;
+typedef struct pjsip_tpmgr pjsip_tpmgr;
/**
* Transport types.
@@ -43,7 +43,6 @@ typedef enum pjsip_transport_type_e
/** UDP. */
PJSIP_TRANSPORT_UDP,
-#if PJ_HAS_TCP
/** TCP. */
PJSIP_TRANSPORT_TCP,
@@ -52,7 +51,6 @@ typedef enum pjsip_transport_type_e
/** SCTP. */
PJSIP_TRANSPORT_SCTP,
-#endif
} pjsip_transport_type_e;