Ignore:
Timestamp:
Dec 30, 2005 11:50:15 PM (18 years ago)
Author:
bennylp
Message:

Basic module, transport, and sending messages

File:
1 edited

Legend:

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

    r105 r106  
    2121 
    2222#include <pjsip/sip_msg.h> 
     23#include <pjsip/sip_resolve.h> 
    2324 
    2425PJ_BEGIN_DECL 
     
    3435 * request outside a dialog, such as OPTIONS, MESSAGE, etc. To create a request 
    3536 * inside a dialog, application should use #pjsip_dlg_create_request. 
     37 * 
     38 * This function adds the following headers in the request: 
     39 *  - From, To, Call-ID, and CSeq, 
     40 *  - Contact header, if contact is specified. 
     41 *  - A blank Via header. 
     42 *  - Additional request headers (such as Max-Forwards) which are copied 
     43 *    from endpoint configuration. 
     44 * 
     45 * In addition, the function adds a unique tag in the From header. 
    3646 * 
    3747 * Once a transmit data is created, the reference counter is initialized to 1. 
     
    6373/** 
    6474 * Create an independent request message from the specified headers. This 
    65  * function will shallow clone the headers and put them in the request. 
     75 * function will clone the headers and put them in the request. 
     76 * 
     77 * This function adds the following headers in the request: 
     78 *  - From, To, Call-ID, and CSeq, 
     79 *  - Contact header, if contact is specified. 
     80 *  - A blank Via header. 
     81 *  - Additional request headers (such as Max-Forwards) which are copied 
     82 *    from endpoint configuration. 
     83 * 
     84 * In addition, the function adds a unique tag in the From header. 
    6685 * 
    6786 * Once a transmit data is created, the reference counter is initialized to 1. 
     
    93112 
    94113/** 
     114 * Construct a minimal response message for the received request. This function 
     115 * will construct all the Via, Record-Route, Call-ID, From, To, CSeq, and  
     116 * Call-ID headers from the request. 
     117 * 
     118 * Note: the txdata reference counter is set to ZERO!. 
     119 * 
     120 * @param endpt     The endpoint. 
     121 * @param rdata     The request receive data. 
     122 * @param st_code   Status code to be put in the response. 
     123 * @param st_text   Optional status text, or NULL to get the default text. 
     124 * @param p_tdata   Pointer to receive the transmit data. 
     125 * 
     126 * @return          PJ_SUCCESS, or the appropriate error code. 
     127 */ 
     128PJ_DECL(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, 
     129                                                  const pjsip_rx_data *rdata, 
     130                                                  int st_code, 
     131                                                  const pj_str_t *st_text, 
     132                                                  pjsip_tx_data **p_tdata); 
     133 
     134/** 
     135 * Construct a full ACK request for the received non-2xx final response. 
     136 * This utility function is normally called by the transaction to construct 
     137 * an ACK request to 3xx-6xx final response. 
     138 * The generation of ACK message for 2xx final response is different than 
     139 * this one. 
     140 *  
     141 * @param endpt     The endpoint. 
     142 * @param tdata     This contains the original INVITE request 
     143 * @param rdata     The final response. 
     144 * @param ack       The ACK request created. 
     145 * 
     146 * @return          PJ_SUCCESS, or the appropriate error code. 
     147 */ 
     148PJ_DECL(pj_status_t) pjsip_endpt_create_ack( pjsip_endpoint *endpt, 
     149                                             const pjsip_tx_data *tdata, 
     150                                             const pjsip_rx_data *rdata, 
     151                                             pjsip_tx_data **ack); 
     152 
     153 
     154/** 
     155 * Construct CANCEL request for the previously sent request. 
     156 * 
     157 * @param endpt     The endpoint. 
     158 * @param tdata     The transmit buffer for the request being cancelled. 
     159 * @param p_tdata   Pointer to receive the transmit data. 
     160 * 
     161 * @return          PJ_SUCCESS, or the appropriate error code. 
     162 */ 
     163PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
     164                                                const pjsip_tx_data *tdata, 
     165                                                pjsip_tx_data **p_tdata); 
     166 
     167 
     168/** 
     169 * Find which destination to be used to send the request message, based 
     170 * on the request URI and Route headers in the message. The procedure 
     171 * used here follows the guidelines on sending the request in RFC 3261 
     172 * chapter 8.1.2. 
     173 * 
     174 * This function may modify the message (request line and Route headers), 
     175 * if the Route information specifies strict routing and the request 
     176 * URI in the message is different than the calculated target URI. In that 
     177 * case, the target URI will be put as the request URI of the request and 
     178 * current request URI will be put as the last entry of the Route headers. 
     179 * 
     180 * @param tdata     The transmit data containing the request message. 
     181 * @param dest_info On return, it contains information about destination 
     182 *                  host to contact, along with the preferable transport 
     183 *                  type, if any. Caller will then normally proceed with 
     184 *                  resolving this host with server resolution procedure 
     185 *                  described in RFC 3263. 
     186 * 
     187 * @return          PJ_SUCCESS, or the appropriate error code. 
     188 */ 
     189PJ_DECL(pj_status_t) pjsip_get_request_addr( pjsip_tx_data *tdata, 
     190                                             pjsip_host_info *dest_info ); 
     191 
     192 
     193/** 
     194 * This structure holds the state of outgoing stateless request. 
     195 */ 
     196typedef struct pjsip_send_state 
     197{ 
     198    /** Application token, which was specified when the function 
     199     *  #pjsip_endpt_send_request_stateless() is called. 
     200     */ 
     201    void *token; 
     202 
     203    /** Endpoint instance.  
     204     */ 
     205    pjsip_endpoint *endpt; 
     206 
     207    /** Transmit data buffer being sent.  
     208     */ 
     209    pjsip_tx_data *tdata; 
     210 
     211    /** Server addresses resolved.  
     212     */ 
     213    pjsip_server_addresses   addr; 
     214 
     215    /** Current server address being tried.  
     216     */ 
     217    unsigned cur_addr; 
     218 
     219    /** Current transport being used.  
     220     */ 
     221    pjsip_transport *cur_transport; 
     222 
     223    /** The application callback which was specified when the function 
     224     *  #pjsip_endpt_send_request_stateless() was called. 
     225     */ 
     226    void (*app_cb)(struct pjsip_send_state*, 
     227                   pj_ssize_t sent, 
     228                   pj_bool_t *cont); 
     229} pjsip_send_state; 
     230 
     231/** 
     232 * Send outgoing request statelessly The function will take care of which  
     233 * destination and transport to use based on the information in the message, 
     234 * taking care of URI in the request line and Route header. 
     235 * 
     236 * This function is different than #pjsip_transport_send() in that this  
     237 * function adds/modify the Via header as necessary. 
     238 * 
     239 * @param endpt     The endpoint instance. 
     240 * @param tdata     The transmit data to be sent. 
     241 * 
     242 * @return          PJ_SUCCESS, or the appropriate error code. 
     243 */ 
     244PJ_DECL(pj_status_t)  
     245pjsip_endpt_send_request_stateless( pjsip_endpoint *endpt, 
     246                                    pjsip_tx_data *tdata, 
     247                                    void *token, 
     248                                    void (*cb)(pjsip_send_state*, 
     249                                               pj_ssize_t sent, 
     250                                               pj_bool_t *cont)); 
     251 
     252/** 
     253 * This structure describes destination information to send response. 
     254 * It is initialized by calling #pjsip_get_response_addr(). 
     255 * 
     256 * If the response message should be sent using transport from which 
     257 * the request was received, then transport, addr, and addr_len fields 
     258 * are initialized. 
     259 * 
     260 * The dst_host field is also initialized. It should be used when server 
     261 * fails to send the response using the transport from which the request 
     262 * was received, or when the transport is NULL, which means server 
     263 * must send the response to this address (this situation occurs when 
     264 * maddr parameter is set, or when rport param is not set in the request). 
     265 */ 
     266typedef struct pjsip_response_addr 
     267{ 
     268    pjsip_transport *transport; /**< Immediate transport to be used. */ 
     269    pj_sockaddr      addr;      /**< Immediate address to send to.   */ 
     270    int              addr_len;  /**< Address length.                 */ 
     271    pjsip_host_info  dst_host;  /**< Destination host to contact.    */ 
     272} pjsip_response_addr; 
     273 
     274/** 
     275 * Determine which address (and transport) to use to send response message 
     276 * based on the received request. This function follows the specification 
     277 * in section 18.2.2 of RFC 3261 and RFC 3581 for calculating the destination 
     278 * address and transport. 
     279 * 
     280 * The information about destination to send the response will be returned 
     281 * in res_addr argument. Please see #pjsip_response_addr for more info. 
     282 * 
     283 * @param pool      The pool. 
     284 * @param rdata     The incoming request received by the server. 
     285 * @param res_addr  On return, it will be initialized with information about 
     286 *                  destination address and transport to send the response. 
     287 * 
     288 * @return          zero (PJ_OK) if successfull. 
     289 */ 
     290PJ_DECL(pj_status_t) pjsip_get_response_addr(pj_pool_t *pool, 
     291                                             pjsip_rx_data *rdata, 
     292                                             pjsip_response_addr *res_addr); 
     293 
     294/** 
     295 * Send response in tdata statelessly. The function will take care of which  
     296 * response destination and transport to use based on the information in the  
     297 * Via header (such as the presence of rport, symmetric transport, etc.). 
     298 * 
     299 * This function will create a new ephemeral transport if no existing  
     300 * transports can be used to send the message to the destination. The ephemeral 
     301 * transport will be destroyed after some period if it is not used to send any  
     302 * more messages. 
     303 * 
     304 * The behavior of this function complies with section 18.2.2 of RFC 3261 
     305 * and RFC 3581. 
     306 * 
     307 * @param endpt     The endpoint instance. 
     308 * @param res_addr  The information about the address and transport to send 
     309 *                  the response to. Application can get this information 
     310 *                  by calling #pjsip_get_response_addr(). 
     311 * @param tdata     The response message to be sent. 
     312 * @param token     Token to be passed back when the callback is called. 
     313 * @param cb        Optional callback to notify the transmission status 
     314 *                  to application, and to inform whether next address or 
     315 *                  transport will be tried. 
     316 *  
     317 * @return          PJ_SUCCESS if response has been successfully created and 
     318 *                  sent to transport layer, or a non-zero error code.  
     319 *                  However, even when it returns PJ_SUCCESS, there is no  
     320 *                  guarantee that the response has been successfully sent. 
     321 */ 
     322PJ_DECL(pj_status_t) pjsip_endpt_send_response( pjsip_endpoint *endpt, 
     323                                                pjsip_response_addr *res_addr, 
     324                                                pjsip_tx_data *tdata, 
     325                                                void *token, 
     326                                                void (*cb)(pjsip_send_state*, 
     327                                                           pj_ssize_t sent, 
     328                                                           pj_bool_t *cont)); 
     329 
     330/** 
    95331 * Send outgoing request and initiate UAC transaction for the request. 
    96332 * This is an auxiliary function to be used by application to send arbitrary 
     
    117353                                               void (*cb)(void*,pjsip_event*)); 
    118354 
    119 /** 
    120  * Construct a minimal response message for the received request. This function 
    121  * will construct all the Via, Record-Route, Call-ID, From, To, CSeq, and  
    122  * Call-ID headers from the request. 
    123  * 
    124  * Note: the txdata reference counter is set to ZERO!. 
    125  * 
    126  * @param endpt     The endpoint. 
    127  * @param rdata     The request receive data. 
    128  * @param code      Status code to be put in the response. 
    129  * @param p_tdata   Pointer to receive the transmit data. 
    130  * 
    131  * @return          PJ_SUCCESS, or the appropriate error code. 
    132  */ 
    133 PJ_DECL(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, 
    134                                                   const pjsip_rx_data *rdata, 
    135                                                   int code, 
    136                                                   pjsip_tx_data **p_tdata); 
    137  
    138 /** 
    139  * Construct a full ACK request for the received non-2xx final response. 
    140  * This utility function is normally called by the transaction to construct 
    141  * an ACK request to 3xx-6xx final response. 
    142  * The generation of ACK message for 2xx final response is different than 
    143  * this one. 
    144  *  
    145  * @param endpt     The endpoint. 
    146  * @param tdata     On input, this contains the original INVITE request, and on 
    147  *                  output, it contains the ACK message. 
    148  * @param rdata     The final response message. 
    149  */ 
    150 PJ_DECL(void) pjsip_endpt_create_ack( pjsip_endpoint *endpt, 
    151                                       pjsip_tx_data *tdata, 
    152                                       const pjsip_rx_data *rdata ); 
    153  
    154  
    155 /** 
    156  * Construct CANCEL request for the previously sent request. 
    157  * 
    158  * @param endpt     The endpoint. 
    159  * @param tdata     The transmit buffer for the request being cancelled. 
    160  * @param p_tdata   Pointer to receive the transmit data. 
    161  * 
    162  * @return          PJ_SUCCESS, or the appropriate error code. 
    163  */ 
    164 PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, 
    165                                                 pjsip_tx_data *tdata, 
    166                                                 pjsip_tx_data **p_tdata); 
    167  
    168  
    169 /** 
    170  * Get the address parameters (host, port, flag, TTL, etc) to send the 
    171  * response. 
    172  * 
    173  * @param pool      The pool. 
    174  * @param tr        The transport where the request was received. 
    175  * @param via       The top-most Via header of the request. 
    176  * @param addr      The send address concluded from the calculation. 
    177  * 
    178  * @return          zero (PJ_OK) if successfull. 
    179  */ 
    180 PJ_DECL(pj_status_t) pjsip_get_response_addr(pj_pool_t *pool, 
    181                                              const pjsip_transport *tr, 
    182                                              const pjsip_via_hdr *via, 
    183                                              pjsip_host_info *addr); 
    184355 
    185356/** 
Note: See TracChangeset for help on using the changeset viewer.