Index: pjproject/trunk/pjsip/include/pjsip/sip_transport.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_transport.h	(revision 742)
+++ pjproject/trunk/pjsip/include/pjsip/sip_transport.h	(revision 879)
@@ -55,4 +55,11 @@
  *
  *****************************************************************************/
+
+/*
+ * Forward declaration for transport factory (since it is referenced by
+ * the transport factory itself).
+ */
+typedef struct pjsip_tpfactory pjsip_tpfactory;
+
 
 /**
@@ -157,4 +164,74 @@
 
 
+
+/*****************************************************************************
+ *
+ * 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;
+    } 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);
+
+
 /*****************************************************************************
  *
@@ -432,4 +509,12 @@
 	int		     dst_port;	    /**< Destination port.	*/
     } tp_info;
+
+    /** 
+     * Transport selector, to specify which transport to be used. 
+     * The value here must be set with pjsip_tx_data_set_transport(),
+     * to allow reference counter to be set properly.
+     */
+    pjsip_tpselector	    tp_sel;
+
 };
 
@@ -499,4 +584,18 @@
  */
 PJ_DECL(char*) pjsip_tx_data_get_info( pjsip_tx_data *tdata );
+
+/**
+ * Set the explicit transport to be used when sending this transmit data.
+ * Application should not need to call this function, but rather use
+ * pjsip_tsx_set_transport() and pjsip_dlg_set_transport() instead (which
+ * will call this function).
+ *
+ * @param tdata	    The transmit buffer.
+ * @param sel	    Transport selector.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjsip_tx_data_set_transport(pjsip_tx_data *tdata,
+						 const pjsip_tpselector *sel);
 
 
@@ -707,10 +806,4 @@
  *****************************************************************************/
 
-/*
- * Forward declaration for transport factory (since it is referenced by
- * the transport factory itself).
- */
-typedef struct pjsip_tpfactory pjsip_tpfactory;
-
 
 /**
@@ -860,4 +953,18 @@
  * Find transport to be used to send message to remote destination. If no
  * suitable transport is found, a new one will be created.
+ *
+ * This is an internal function since normally application doesn't have access
+ * to transport manager. Application should use pjsip_endpt_acquire_transport()
+ * instead.
+ *
+ * @param mgr	    The transport manager instance.
+ * @param type	    The type of transport to be acquired.
+ * @param remote    The remote address to send message to.
+ * @param addr_len  Length of the remote address.
+ * @param sel	    Optional pointer to transport selector instance which is
+ *		    used to find explicit transport, if required.
+ * @param tp	    Pointer to receive the transport instance, if one is found.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
  */
 PJ_DECL(pj_status_t) pjsip_tpmgr_acquire_transport(pjsip_tpmgr *mgr,
@@ -865,4 +972,5 @@
 						   const pj_sockaddr_t *remote,
 						   int addr_len,
+						   const pjsip_tpselector *sel,
 						   pjsip_transport **tp);
 
