Ignore:
Timestamp:
Mar 1, 2007 12:08:27 AM (17 years ago)
Author:
bennylp
Message:

More work on STUN session framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/include/pjlib-util/stun_session.h

    r1008 r1021  
    2525#include <pj/list.h> 
    2626 
     27PJ_BEGIN_DECL 
     28 
     29 
     30/* **************************************************************************/ 
     31/** 
     32 * @defgroup PJLIB_UTIL_STUN_SESSION STUN Client/Server Session 
     33 * @brief STUN client and server session 
     34 * @ingroup PJLIB_UTIL_STUN 
     35 * @{ 
     36 */ 
     37 
    2738 
    2839/** Forward declaration for pj_stun_tx_data */ 
     
    3142/** Forward declaration for pj_stun_session */ 
    3243typedef struct pj_stun_session pj_stun_session; 
     44 
    3345 
    3446/** 
     
    5264     *                      packet sending. 
    5365     */ 
    54     pj_status_t (*on_send_msg)(pj_stun_tx_data *tdata, 
     66    pj_status_t (*on_send_msg)(pj_stun_session *sess, 
    5567                               const void *pkt, 
    5668                               pj_size_t pkt_size, 
    57                                unsigned addr_len,  
    58                                const pj_sockaddr_t *dst_addr); 
    59  
    60     /** 
    61      * Callback to be called when Binding response is received or the  
    62      * transaction has timed out. 
     69                               const pj_sockaddr_t *dst_addr, 
     70                               unsigned addr_len); 
     71 
     72    /**  
     73     * Callback to be called on incoming STUN request message. In the  
     74     * callback processing, application MUST create a response by calling 
     75     * pj_stun_session_create_response() function and send the response 
     76     * with pj_stun_session_send_msg() function, before returning from 
     77     * the callback. 
     78     * 
     79     * @param sess          The STUN session. 
     80     * @param pkt           Pointer to the original STUN packet. 
     81     * @param pkt_len       Length of the STUN packet. 
     82     * @param msg           The parsed STUN request. 
     83     * @param src_addr      Source address of the packet. 
     84     * @param src_addr_len  Length of the source address. 
     85     * 
     86     * @return              The return value of this callback will be 
     87     *                      returned back to pj_stun_session_on_rx_pkt() 
     88     *                      function. 
     89     */ 
     90    pj_status_t (*on_rx_request)(pj_stun_session *sess, 
     91                                 const pj_uint8_t *pkt, 
     92                                 unsigned pkt_len, 
     93                                 const pj_stun_msg *msg, 
     94                                 const pj_sockaddr_t *src_addr, 
     95                                 unsigned src_addr_len); 
     96 
     97    /** 
     98     * Callback to be called when response is received or the transaction  
     99     * has timed out. 
    63100     * 
    64101     * @param sess          The STUN session. 
     
    70107     * @param response      The response message, on successful transaction. 
    71108     */ 
    72     void (*on_bind_response)(pj_stun_session *sess,  
    73                              pj_status_t status,  
    74                              pj_stun_tx_data *request, 
    75                              const pj_stun_msg *response); 
    76  
    77     /** 
    78      * Callback to be called when Allocate response is received or the  
    79      * transaction has timed out. 
    80      * 
    81      * @param sess          The STUN session. 
    82      * @param status        Status of the request. If the value if not 
    83      *                      PJ_SUCCESS, the transaction has timed-out 
    84      *                      or other error has occurred, and the response 
    85      *                      argument may be NULL. 
    86      * @param request       The original STUN request. 
    87      * @param response      The response message, on successful transaction. 
    88      */ 
    89     void (*on_allocate_response)(pj_stun_session *sess,  
    90                                  pj_status_t status,  
    91                                  pj_stun_tx_data *request, 
    92                                  const pj_stun_msg *response); 
    93  
    94     /** 
    95      * Callback to be called when Set Active Destination response is received 
    96      * or the transaction has timed out. 
    97      * 
    98      * @param sess          The STUN session. 
    99      * @param status        Status of the request. If the value if not 
    100      *                      PJ_SUCCESS, the transaction has timed-out 
    101      *                      or other error has occurred, and the response 
    102      *                      argument may be NULL. 
    103      * @param request       The original STUN request. 
    104      * @param response      The response message, on successful transaction. 
    105      */ 
    106     void (*on_set_active_destination_response)(pj_stun_session *sess,  
    107                                                pj_status_t status,  
    108                                                pj_stun_tx_data *request, 
    109                                                const pj_stun_msg *response); 
    110  
    111     /** 
    112      * Callback to be called when Connect response is received or the  
    113      * transaction has timed out. 
    114      * 
    115      * @param sess          The STUN session. 
    116      * @param status        Status of the request. If the value if not 
    117      *                      PJ_SUCCESS, the transaction has timed-out 
    118      *                      or other error has occurred, and the response 
    119      *                      argument may be NULL. 
    120      * @param request       The original STUN request. 
    121      * @param response      The response message, on successful transaction. 
    122      */ 
    123     void (*on_connect_response)( pj_stun_session *sess,  
    124                                  pj_status_t status,  
    125                                  pj_stun_tx_data *request, 
    126                                  const pj_stun_msg *response); 
     109    void (*on_request_complete)(pj_stun_session *sess, 
     110                                pj_status_t status, 
     111                                pj_stun_tx_data *tdata, 
     112                                const pj_stun_msg *response); 
     113 
     114 
     115    /** 
     116     * Type of callback to be called on incoming STUN indication. 
     117     */ 
     118    pj_status_t (*on_rx_indication)(pj_stun_session *sess, 
     119                                    const pj_uint8_t *pkt, 
     120                                    unsigned pkt_len, 
     121                                    const pj_stun_msg *msg, 
     122                                    const pj_sockaddr_t *src_addr, 
     123                                    unsigned src_addr_len); 
     124 
    127125} pj_stun_session_cb; 
    128126 
     
    360358PJ_DECL(pj_status_t) pj_stun_session_create_data_ind(pj_stun_session *sess, 
    361359                                                     pj_stun_tx_data **p_tdata); 
     360 
     361/** 
     362 * Create a STUN response message. After the message has been  
     363 * successfully created, application can send the message by calling  
     364 * pj_stun_session_send_msg(). 
     365 * 
     366 * @param sess      The STUN session instance. 
     367 * @param req       The STUN request where the response is to be created. 
     368 * @param err_code  Error code to be set in the response, if error response 
     369 *                  is to be created, according to pj_stun_status enumeration. 
     370 *                  This argument MUST be zero if successful response is 
     371 *                  to be created. 
     372 * @param err_msg   Optional pointer for the error message string, when 
     373 *                  creating error response. If the value is NULL and the 
     374 *                  \a err_code is non-zero, then default error message will 
     375 *                  be used. 
     376 * @param p_tdata   Pointer to receive the response message created. 
     377 * 
     378 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     379 */ 
     380PJ_DECL(pj_status_t) pj_stun_session_create_response(pj_stun_session *sess, 
     381                                                     const pj_stun_msg *req, 
     382                                                     unsigned err_code, 
     383                                                     const pj_str_t *err_msg, 
     384                                                     pj_stun_tx_data **p_tdata); 
     385 
    362386 
    363387/** 
     
    373397 * @param sess      The STUN session instance. 
    374398 * @param options   Optional flags, from pj_stun_session_option. 
     399 * @param dst_addr  The destination socket address. 
    375400 * @param addr_len  Length of destination address. 
    376  * @param dst_addr  The destination socket address. 
    377401 * @param tdata     The STUN transmit data containing the STUN message to 
    378402 *                  be sent. 
     
    382406PJ_DECL(pj_status_t) pj_stun_session_send_msg(pj_stun_session *sess, 
    383407                                              unsigned options, 
     408                                              const pj_sockaddr_t *dst_addr, 
    384409                                              unsigned addr_len, 
    385                                               const pj_sockaddr_t *dst_addr, 
    386410                                              pj_stun_tx_data *tdata); 
    387411 
     
    403427 * @param packet     The packet containing STUN message. 
    404428 * @param pkt_size   Size of the packet. 
     429 * @param options    Options, from pj_stun_options. 
    405430 * @param parsed_len Optional pointer to receive the size of the parsed 
    406431 *                   STUN message (useful if packet is received via a 
     
    412437                                               const void *packet, 
    413438                                               pj_size_t pkt_size, 
    414                                                unsigned *parsed_len); 
    415  
    416  
     439                                               unsigned options, 
     440                                               unsigned *parsed_len, 
     441                                               const pj_sockaddr_t *src_addr, 
     442                                               unsigned src_addr_len); 
     443 
     444/** 
     445 * Destroy the transmit data. Call this function only when tdata has been 
     446 * created but application doesn't want to send the message (perhaps 
     447 * because of other error). 
     448 * 
     449 * @param sess      The STUN session. 
     450 * @param tdata     The transmit data. 
     451 * 
     452 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     453 */ 
     454PJ_DECL(void) pj_stun_msg_destroy_tdata(pj_stun_session *sess, 
     455                                        pj_stun_tx_data *tdata); 
     456 
     457 
     458/** 
     459 * @} 
     460 */ 
     461 
     462 
     463PJ_END_DECL 
    417464 
    418465#endif  /* __PJLIB_UTIL_STUN_SESSION_H__ */ 
Note: See TracChangeset for help on using the changeset viewer.