Ignore:
Timestamp:
Jan 12, 2007 6:37:35 AM (17 years ago)
Author:
bennylp
Message:

Workaround for ticket #50: added API to lock/bind transaction, dialog, and regc to a specific transport/listener

Location:
pjproject/trunk/pjsip/include/pjsip
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_dialog.h

    r729 r879  
    2929#include <pjsip/sip_auth.h> 
    3030#include <pjsip/sip_errno.h> 
     31#include <pjsip/sip_transport.h> 
    3132#include <pj/sock.h> 
    3233#include <pj/assert.h> 
     
    135136    int                 tsx_count;  /**< Number of pending transactions.    */ 
    136137 
     138    /** Transport selector. */ 
     139    pjsip_tpselector    tp_sel; 
     140 
    137141    /* Dialog usages. */ 
    138142    unsigned            usage_cnt;  /**< Number of registered usages.       */ 
     
    225229 
    226230/** 
     231 * Lock/bind dialog to a specific transport/listener. This is optional, 
     232 * as normally transport will be selected automatically based on the  
     233 * destination of requests upon resolver completion. When the dialog is  
     234 * explicitly bound to the specific transport/listener, all UAC transactions 
     235 * originated by this dialog will use the specified transport/listener 
     236 * when sending outgoing requests. 
     237 * 
     238 * Note that this doesn't affect the Contact header generated by this 
     239 * dialog. Application must manually update the Contact header if 
     240 * necessary, to adjust the address according to the transport being 
     241 * selected. 
     242 * 
     243 * @param dlg       The dialog instance. 
     244 * @param sel       Transport selector containing the specification of 
     245 *                  transport or listener to be used by this dialog 
     246 *                  to send requests. 
     247 * 
     248 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     249 */ 
     250PJ_DECL(pj_status_t) pjsip_dlg_set_transport(pjsip_dialog *dlg, 
     251                                             const pjsip_tpselector *sel); 
     252 
     253 
     254/** 
    227255 * Create a new (forked) dialog on receipt on forked response in rdata.  
    228256 * The new dialog will be created from original_dlg, except that it will have 
  • pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h

    r797 r879  
    353353/** 
    354354 * Find a SIP transport suitable for sending SIP message to the specified 
    355  * address. This function will complete asynchronously when the transport is 
    356  * ready (for example, when TCP socket is connected), and when it completes, 
    357  * the callback will be called with the status of the operation. 
    358  * 
    359  * @see pjsip_transport_get 
     355 * address. If transport selector ("sel") is set, then the function will 
     356 * check if the transport selected is suitable to send requests to the 
     357 * specified address. 
     358 * 
     359 * @see pjsip_tpmgr_acquire_transport 
     360 * 
     361 * @param endpt     The SIP endpoint instance. 
     362 * @param type      The type of transport to be acquired. 
     363 * @param remote    The remote address to send message to. 
     364 * @param addr_len  Length of the remote address. 
     365 * @param sel       Optional pointer to transport selector instance which is 
     366 *                  used to find explicit transport, if required. 
     367 * @param p_tp      Pointer to receive the transport instance, if one is found. 
     368 * 
     369 * @return          PJ_SUCCESS on success, or the appropriate error code. 
    360370 */ 
    361371PJ_DECL(pj_status_t)  
     
    364374                               const pj_sockaddr_t *remote, 
    365375                               int addr_len, 
    366                                pjsip_transport **p_transport); 
     376                               const pjsip_tpselector *sel, 
     377                               pjsip_transport **p_tp); 
    367378 
    368379 
  • pjproject/trunk/pjsip/include/pjsip/sip_errno.h

    r871 r879  
    215215 */ 
    216216#define PJSIP_EBUFDESTROYED     (PJSIP_ERRNO_START_PJSIP + 63)  /* 171063 */ 
     217/** 
     218 * @hideinitializer 
     219 * Unsuitable transport selected. This error occurs when application 
     220 * has explicitly requested to use a particular transport/listener, 
     221 * but the selected transport is not suitable to send request to 
     222 * the specified destination. 
     223 */ 
     224#define PJSIP_ETPNOTSUITABLE    (PJSIP_ERRNO_START_PJSIP + 64)  /* 171064 */ 
    217225 
    218226 
  • pjproject/trunk/pjsip/include/pjsip/sip_transaction.h

    r622 r879  
    2727#include <pjsip/sip_msg.h> 
    2828#include <pjsip/sip_util.h> 
     29#include <pjsip/sip_transport.h> 
    2930#include <pj/timer.h> 
    3031 
     
    9798    pj_uint32_t                 hashed_key;     /**< Key's hashed value.    */ 
    9899    pj_str_t                    branch;         /**< The branch Id.         */ 
     100    pjsip_tpselector            tp_sel;         /**< Transport selector.    */ 
    99101 
    100102    /* 
     
    215217 
    216218/** 
     219 * Lock/bind transaction to a specific transport/listener. This is optional, 
     220 * as normally transport will be selected automatically based on the  
     221 * destination of the request upon resolver completion. Also it's only valid 
     222 * for UAC transaction (to send outgoing request), since for UAS the 
     223 * transport will be selected according to rules about handling incoming 
     224 * request (most likely it will use the transport where the request is 
     225 * coming from if ";rport" parameter is present in Via header). 
     226 * 
     227 * @param tsx       The UAC transaction. 
     228 * @param sel       Transport selector containing the specification of 
     229 *                  transport or listener to be used by this transaction 
     230 *                  to send requests. 
     231 * 
     232 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     233 */ 
     234PJ_DECL(pj_status_t) pjsip_tsx_set_transport(pjsip_transaction *tsx, 
     235                                             const pjsip_tpselector *sel); 
     236 
     237 
     238/** 
    217239 * Call this function to manually feed a message to the transaction. 
    218240 * For UAS transaction, application MUST call this function after 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r742 r879  
    5555 * 
    5656 *****************************************************************************/ 
     57 
     58/* 
     59 * Forward declaration for transport factory (since it is referenced by 
     60 * the transport factory itself). 
     61 */ 
     62typedef struct pjsip_tpfactory pjsip_tpfactory; 
     63 
    5764 
    5865/** 
     
    157164 
    158165 
     166 
     167/***************************************************************************** 
     168 * 
     169 * TRANSPORT SELECTOR. 
     170 * 
     171 *****************************************************************************/ 
     172 
     173/** 
     174 * This structure describes the type of data in pjsip_tpselector. 
     175 */ 
     176typedef enum pjsip_tpselector_type 
     177{ 
     178    /** Transport is not specified. */ 
     179    PJSIP_TPSELECTOR_NONE, 
     180 
     181    /** Use the specific transport to send request. */ 
     182    PJSIP_TPSELECTOR_TRANSPORT, 
     183 
     184    /** Use the specific listener to send request. */ 
     185    PJSIP_TPSELECTOR_LISTENER, 
     186 
     187} pjsip_tpselector_type; 
     188 
     189 
     190/** 
     191 * This structure describes the transport/listener preference to be used 
     192 * when sending outgoing requests. 
     193 * 
     194 * Normally transport will be selected automatically according to rules about 
     195 * sending requests. But some applications (such as proxies or B2BUAs) may  
     196 * want to explicitly use specific transport to send requests, for example 
     197 * when they want to make sure that outgoing request should go from a specific 
     198 * network interface. 
     199 * 
     200 * The pjsip_tpselector structure is used for that purpose, i.e. to allow 
     201 * application specificly request that a particular transport/listener 
     202 * should be used to send request. This structure is used when calling 
     203 * pjsip_tsx_set_transport() and pjsip_dlg_set_transport(). 
     204 */ 
     205typedef struct pjsip_tpselector 
     206{ 
     207    /** The type of data in the union */ 
     208    pjsip_tpselector_type   type; 
     209 
     210    /** Union representing the transport/listener criteria to be used. */ 
     211    union { 
     212        pjsip_transport *transport; 
     213        pjsip_tpfactory *listener; 
     214    } u; 
     215 
     216} pjsip_tpselector; 
     217 
     218 
     219/** 
     220 * Add transport/listener reference in the selector to prevent the specified 
     221 * transport/listener from being destroyed while application still has 
     222 * reference to it. 
     223 * 
     224 * @param sel   The transport selector. 
     225 */ 
     226PJ_DECL(void) pjsip_tpselector_add_ref(pjsip_tpselector *sel); 
     227 
     228 
     229/** 
     230 * Decrement transport/listener reference in the selector. 
     231 * @param sel   The transport selector 
     232 */ 
     233PJ_DECL(void) pjsip_tpselector_dec_ref(pjsip_tpselector *sel); 
     234 
     235 
    159236/***************************************************************************** 
    160237 * 
     
    432509        int                  dst_port;      /**< Destination port.      */ 
    433510    } tp_info; 
     511 
     512    /**  
     513     * Transport selector, to specify which transport to be used.  
     514     * The value here must be set with pjsip_tx_data_set_transport(), 
     515     * to allow reference counter to be set properly. 
     516     */ 
     517    pjsip_tpselector        tp_sel; 
     518 
    434519}; 
    435520 
     
    499584 */ 
    500585PJ_DECL(char*) pjsip_tx_data_get_info( pjsip_tx_data *tdata ); 
     586 
     587/** 
     588 * Set the explicit transport to be used when sending this transmit data. 
     589 * Application should not need to call this function, but rather use 
     590 * pjsip_tsx_set_transport() and pjsip_dlg_set_transport() instead (which 
     591 * will call this function). 
     592 * 
     593 * @param tdata     The transmit buffer. 
     594 * @param sel       Transport selector. 
     595 * 
     596 * @return          PJ_SUCCESS on success. 
     597 */ 
     598PJ_DECL(pj_status_t) pjsip_tx_data_set_transport(pjsip_tx_data *tdata, 
     599                                                 const pjsip_tpselector *sel); 
    501600 
    502601 
     
    707806 *****************************************************************************/ 
    708807 
    709 /* 
    710  * Forward declaration for transport factory (since it is referenced by 
    711  * the transport factory itself). 
    712  */ 
    713 typedef struct pjsip_tpfactory pjsip_tpfactory; 
    714  
    715808 
    716809/** 
     
    860953 * Find transport to be used to send message to remote destination. If no 
    861954 * suitable transport is found, a new one will be created. 
     955 * 
     956 * This is an internal function since normally application doesn't have access 
     957 * to transport manager. Application should use pjsip_endpt_acquire_transport() 
     958 * instead. 
     959 * 
     960 * @param mgr       The transport manager instance. 
     961 * @param type      The type of transport to be acquired. 
     962 * @param remote    The remote address to send message to. 
     963 * @param addr_len  Length of the remote address. 
     964 * @param sel       Optional pointer to transport selector instance which is 
     965 *                  used to find explicit transport, if required. 
     966 * @param tp        Pointer to receive the transport instance, if one is found. 
     967 * 
     968 * @return          PJ_SUCCESS on success, or the appropriate error code. 
    862969 */ 
    863970PJ_DECL(pj_status_t) pjsip_tpmgr_acquire_transport(pjsip_tpmgr *mgr, 
     
    865972                                                   const pj_sockaddr_t *remote, 
    866973                                                   int addr_len, 
     974                                                   const pjsip_tpselector *sel, 
    867975                                                   pjsip_transport **tp); 
    868976 
Note: See TracChangeset for help on using the changeset viewer.