Ignore:
Timestamp:
Jan 5, 2006 11:35:46 PM (18 years ago)
Author:
bennylp
Message:

Added loop transport to test transaction

File:
1 edited

Legend:

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

    r105 r107  
    2626 
    2727#include <pjsip/sip_msg.h> 
    28 #include <pjsip/sip_resolve.h> 
     28#include <pjsip/sip_util.h> 
    2929#include <pj/timer.h> 
    3030 
     
    3737 */ 
    3838 
    39 /* Forward decl. */ 
    40 struct pjsip_transaction; 
    41  
    42  
    43 /** 
    44  * Transaction state. 
     39/** 
     40 * This enumeration represents transaction state. 
    4541 */ 
    4642typedef enum pjsip_tsx_state_e 
    4743{ 
    48     PJSIP_TSX_STATE_NULL, 
    49     PJSIP_TSX_STATE_CALLING, 
    50     PJSIP_TSX_STATE_TRYING, 
    51     PJSIP_TSX_STATE_PROCEEDING, 
    52     PJSIP_TSX_STATE_COMPLETED, 
    53     PJSIP_TSX_STATE_CONFIRMED, 
    54     PJSIP_TSX_STATE_TERMINATED, 
    55     PJSIP_TSX_STATE_DESTROYED, 
    56     PJSIP_TSX_STATE_MAX, 
     44    PJSIP_TSX_STATE_NULL,       /**< For UAC, before any message is sent.   */ 
     45    PJSIP_TSX_STATE_CALLING,    /**< For UAC, just after request is sent.   */ 
     46    PJSIP_TSX_STATE_TRYING,     /**< For UAS, just after request is received.*/ 
     47    PJSIP_TSX_STATE_PROCEEDING, /**< For UAS/UAC, after provisional response.*/ 
     48    PJSIP_TSX_STATE_COMPLETED,  /**< For UAS/UAC, after final response.     */ 
     49    PJSIP_TSX_STATE_CONFIRMED,  /**< For UAS, after ACK is received.        */ 
     50    PJSIP_TSX_STATE_TERMINATED, /**< For UAS/UAC, before it's destroyed.    */ 
     51    PJSIP_TSX_STATE_DESTROYED,  /**< For UAS/UAC, will be destroyed now.    */ 
     52    PJSIP_TSX_STATE_MAX,        /**< Number of states.                      */ 
    5753} pjsip_tsx_state_e; 
    5854 
    5955 
    6056/** 
    61  * State of the transport in the transaction. 
    62  * The transport is progressing independently of the transaction. 
    63  */ 
    64 typedef enum pjsip_tsx_transport_state_e 
    65 { 
    66     PJSIP_TSX_TRANSPORT_STATE_NULL, 
    67     PJSIP_TSX_TRANSPORT_STATE_RESOLVING, 
    68     PJSIP_TSX_TRANSPORT_STATE_CONNECTING, 
    69     PJSIP_TSX_TRANSPORT_STATE_FINAL, 
    70 } pjsip_tsx_transport_state_e; 
    71  
    72  
    73 /** 
    74  * Transaction state. 
     57 * This structure describes SIP transaction object. The transaction object 
     58 * is used to handle both UAS and UAC transaction. 
    7559 */ 
    7660struct pjsip_transaction 
     
    8064     */ 
    8165    pj_pool_t                  *pool;           /**< Pool owned by the tsx. */ 
     66    pjsip_module               *tsx_user;       /**< Transaction user.      */ 
    8267    pjsip_endpoint             *endpt;          /**< Endpoint instance.     */ 
    8368    pj_mutex_t                 *mutex;          /**< Mutex for this tsx.    */ 
    84     char                        obj_name[PJ_MAX_OBJ_NAME];  /**< Tsx name.  */ 
    85     int                         tracing;        /**< Tracing enabled?       */ 
    8669 
    8770    /* 
    8871     * Transaction identification. 
    8972     */ 
     73    char                        obj_name[PJ_MAX_OBJ_NAME];  /**< Log info.  */ 
    9074    pjsip_role_e                role;           /**< Role (UAS or UAC)      */ 
    9175    pjsip_method                method;         /**< The method.            */ 
    9276    int                         cseq;           /**< The CSeq               */ 
    93     pj_str_t                    transaction_key;/**< hash table key.        */ 
     77    pj_str_t                    transaction_key;/**< Hash table key.        */ 
    9478    pj_str_t                    branch;         /**< The branch Id.         */ 
    9579 
     
    9983    int                         status_code;    /**< Last status code seen. */ 
    10084    pjsip_tsx_state_e           state;          /**< State.                 */ 
    101     int                         handle_ack;     /**< Should we handle ACK?  */ 
     85    int                         handle_200resp; /**< UAS 200/INVITE  retrsm.*/ 
     86    int                         tracing;        /**< Tracing enabled?       */ 
    10287 
    10388    /** Handler according to current state. */ 
     
    10792     * Transport. 
    10893     */ 
    109     pjsip_tsx_transport_state_e transport_state;/**< Transport's state.     */ 
    110     pjsip_host_info             dest_name;      /**< Destination address.   */ 
    111     pjsip_server_addresses      remote_addr;    /**< Addresses resolved.    */ 
    112     int                         current_addr;   /**< Address currently used. */ 
    113  
    11494    pjsip_transport            *transport;      /**< Transport to use.      */ 
     95    pj_sockaddr                 addr;           /**< Destination address.   */ 
     96    int                         addr_len;       /**< Address length.        */ 
     97    pjsip_response_addr         res_addr;       /**< Response address.      */ 
     98    unsigned                    transport_flag; /**< Miscelaneous flag.     */ 
    11599 
    116100    /* 
     
    118102     */ 
    119103    pjsip_tx_data              *last_tx;        /**< Msg kept for retrans.  */ 
    120     int                         has_unsent_msg; /**< Non-zero if tsx need to  
    121                                                      transmit msg once resolver 
    122                                                      completes.             */ 
    123104    int                         retransmit_count;/**< Retransmission count. */ 
    124105    pj_timer_entry              retransmit_timer;/**< Retransmit timer.     */ 
     
    126107 
    127108    /** Module specific data. */ 
    128     void                       *module_data[PJSIP_MAX_MODULE]; 
     109    void                       *mod_data[PJSIP_MAX_MODULE]; 
    129110}; 
    130111 
    131112 
    132113/** 
    133  * Create new transaction. Application would normally use  
    134  * #pjsip_endpt_create_tsx rather than this function. 
    135  * 
    136  * @param pool      Pool to use by the transaction. 
    137  * @param endpt     Endpoint. 
    138  * @param p_tsx     Pointer to return the transaction. 
    139  * 
    140  * @return          PJ_SUCCESS or the appropriate error code. 
    141  * 
    142  * @see pjsip_endpt_create_tsx 
    143  * 
    144  */ 
    145 PJ_DEF(pj_status_t) pjsip_tsx_create( pj_pool_t *pool, 
    146                                       pjsip_endpoint *endpt, 
    147                                       pjsip_transaction **p_tsx); 
    148  
    149 /**  
    150  * Init transaction as UAC from the specified transmit data (\c tdata). 
    151  * The transmit data must have a valid \c Request-Line and \c CSeq header. 
    152  * If \c Route headers are present, it will be used to calculate remote 
    153  * destination. 
     114 * Create and register transaction layer module to the specified endpoint. 
     115 * 
     116 * @param endpt     The endpoint instance. 
     117 * 
     118 * @return          PJ_SUCCESS on success. 
     119 */ 
     120PJ_DECL(pj_status_t) pjsip_tsx_layer_init(pjsip_endpoint *endpt); 
     121 
     122/** 
     123 * Get the instance of the transaction layer module. 
     124 * 
     125 * @return          The transaction layer module. 
     126 */ 
     127PJ_DECL(pjsip_module*) pjsip_tsx_layer_instance(void); 
     128 
     129/** 
     130 * Unregister and destroy transaction layer module. 
     131 * 
     132 * @return          PJ_SUCCESS on success. 
     133 */ 
     134PJ_DECL(pj_status_t) pjsip_tsx_layer_destroy(void); 
     135 
     136/** 
     137 * Find a transaction with the specified key. The transaction key normally 
     138 * is created by calling #pjsip_tsx_create_key() from an incoming message. 
     139 * 
     140 * @param key       The key string to find the transaction. 
     141 * @param lock      If non-zero, transaction will be locked before the 
     142 *                  function returns, to make sure that it's not deleted 
     143 *                  by other threads. 
     144 * 
     145 * @return          The matching transaction instance, or NULL if transaction 
     146 *                  can not be found. 
     147 */ 
     148PJ_DECL(pjsip_transaction*) pjsip_tsx_layer_find_tsx( const pj_str_t *key, 
     149                                                      pj_bool_t lock ); 
     150 
     151/** 
     152 * Create, initialize, and register a new transaction as UAC from the  
     153 * specified transmit data (\c tdata). The transmit data must have a valid 
     154 * \c Request-Line and \c CSeq header.  
    154155 * 
    155156 * If \c Via header does not exist, it will be created along with a unique 
    156157 * \c branch parameter. If it exists and contains branch parameter, then 
    157  * the \c branch parameter will be used as is as the transaction key. 
    158  * 
    159  * The \c Route headers in the transmit data, if present, are used to  
    160  * calculate remote destination. 
    161  * 
    162  * At the end of the function, the transaction will start resolving the 
    163  * addresses of remote server to contact. Transport will be acquired as soon 
    164  * as the resolving job completes. 
    165  * 
    166  * @param tsx       The transaction. 
    167  * @param tdata     The transmit data. 
     158 * the \c branch parameter will be used as is as the transaction key. If 
     159 * it exists but branch parameter doesn't exist, a unique branch parameter 
     160 * will be created. 
     161 * 
     162 * @param tsx_user  Module to be registered as transaction user of the new 
     163 *                  transaction, which will receive notification from the 
     164 *                  transaction via on_tsx_state() callback. 
     165 * @param tdata     The outgoing request message. 
     166 * @param p_tsx     On return will contain the new transaction instance. 
    168167 * 
    169168 * @return          PJ_SUCCESS if successfull. 
    170169 */ 
    171 PJ_DECL(pj_status_t) pjsip_tsx_init_uac( pjsip_transaction *tsx,  
    172                                          pjsip_tx_data *tdata); 
    173  
    174 /** 
    175  * Init transaction as UAS. 
    176  * 
    177  * @param tsx       The transaction to be initialized. 
     170PJ_DECL(pj_status_t) pjsip_tsx_create_uac( pjsip_module *tsx_user, 
     171                                           pjsip_tx_data *tdata, 
     172                                           pjsip_transaction **p_tsx); 
     173 
     174/** 
     175 * Create, initialize, and register a new transaction as UAS from the 
     176 * specified incoming request in \c rdata. 
     177 * 
     178 * @param tsx_user  Module to be registered as transaction user of the new 
     179 *                  transaction, which will receive notification from the 
     180 *                  transaction via on_tsx_state() callback. 
    178181 * @param rdata     The received incoming request. 
    179  * 
    180  * @return PJ_SUCCESS if successfull. 
    181  */ 
    182 PJ_DECL(pj_status_t) pjsip_tsx_init_uas( pjsip_transaction *tsx, 
    183                                          pjsip_rx_data *rdata); 
    184  
    185 /** 
    186  * Process incoming message for this transaction. 
    187  * 
    188  * @param tsx       The transaction. 
    189  * @param rdata     The incoming message. 
    190  */ 
    191 PJ_DECL(void) pjsip_tsx_on_rx_msg( pjsip_transaction *tsx, 
    192                                    pjsip_rx_data *rdata); 
    193  
    194 /** 
    195  * Transmit message with this transaction. 
     182 * @param p_tsx     On return will contain the new transaction instance. 
     183 * 
     184 * @return          PJ_SUCCESS if successfull. 
     185 */ 
     186PJ_DECL(pj_status_t) pjsip_tsx_create_uas( pjsip_module *tsx_user, 
     187                                           pjsip_rx_data *rdata, 
     188                                           pjsip_transaction **p_tsx ); 
     189 
     190/** 
     191 * Transmit message in tdata with this transaction. It is possible to 
     192 * pass NULL in tdata for UAC transaction, which in this case the request 
     193 * message which was specified in #pjsip_tsx_create_uac() will be sent. 
    196194 * 
    197195 * @param tsx       The transaction. 
    198196 * @param tdata     The outgoing message. 
    199  */ 
    200 PJ_DECL(void) pjsip_tsx_on_tx_msg( pjsip_transaction *tsx, 
    201                                    pjsip_tx_data *tdata); 
    202  
    203  
    204 /** 
    205  * Transmit ACK message for 2xx/INVITE with this transaction. The ACK for 
    206  * non-2xx/INVITE is automatically sent by the transaction. 
    207  * This operation is only valid if the transaction is configured to handle ACK 
    208  * (tsx->handle_ack is non-zero). If this attribute is not set, then the 
    209  * transaction will comply with RFC-3261, i.e. it will set itself to  
    210  * TERMINATED state when it receives 2xx/INVITE. 
    211  * 
    212  * @param tsx       The transaction. 
    213  * @param tdata     The ACK request. 
    214  */ 
    215 PJ_DECL(void) pjsip_tsx_on_tx_ack( pjsip_transaction *tsx, 
    216                                    pjsip_tx_data *tdata); 
    217  
    218 /** 
    219  * Force terminate transaction. 
    220  * 
    221  * @param tsx       The transaction. 
    222  * @param code      The status code to report. 
    223  */ 
    224 PJ_DECL(void) pjsip_tsx_terminate( pjsip_transaction *tsx, 
    225                                    int code ); 
     197 * 
     198 * @return          PJ_SUCCESS if successfull. 
     199 */ 
     200PJ_DECL(pj_status_t) pjsip_tsx_send_msg( pjsip_transaction *tsx, 
     201                                         pjsip_tx_data *tdata); 
     202 
    226203 
    227204/** 
     
    245222 
    246223/** 
     224 * Force terminate transaction. 
     225 * 
     226 * @param tsx       The transaction. 
     227 * @param code      The status code to report. 
     228 */ 
     229PJ_DECL(pj_status_t) pjsip_tsx_terminate( pjsip_transaction *tsx, 
     230                                          int st_code ); 
     231 
     232 
     233/** 
     234 * Get the transaction instance in the incoming message. If the message 
     235 * has a corresponding transaction, this function will return non NULL 
     236 * value. 
     237 * 
     238 * @param rdata     The incoming message buffer. 
     239 * 
     240 * @return          The transaction instance associated with this message, 
     241 *                  or NULL if the message doesn't match any transactions. 
     242 */ 
     243PJ_DECL(pjsip_transaction*) pjsip_rdata_get_tsx( pjsip_rx_data *rdata ); 
     244 
     245 
     246/** 
    247247 * @} 
    248248 */ 
     
    263263 
    264264 
    265 /* Thread Local Storage ID for transaction lock (initialized by endpoint) */ 
    266 extern long pjsip_tsx_lock_tls_id; 
    267  
    268265PJ_END_DECL 
    269266 
Note: See TracChangeset for help on using the changeset viewer.