📄 sip_util.h
字号:
/* $Id: sip_util.h 1121 2007-04-01 22:58:47Z bennylp $ *//* * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef __PJSIP_SIP_MISC_H__#define __PJSIP_SIP_MISC_H__#include <pjsip/sip_msg.h>#include <pjsip/sip_resolve.h>PJ_BEGIN_DECL/** * @defgroup PJSIP_ENDPT_STATELESS Message Creation and Stateless Operations * @ingroup PJSIP_CORE_CORE * @brief Utilities to create various messages and base function to send messages. * @{ *//** * Create an independent request message. This can be used to build any * request outside a dialog, such as OPTIONS, MESSAGE, etc. To create a request * inside a dialog, application should use #pjsip_dlg_create_request. * * This function adds the following headers in the request: * - From, To, Call-ID, and CSeq, * - Contact header, if contact is specified. * - A blank Via header. * - Additional request headers (such as Max-Forwards) which are copied * from endpoint configuration. * * In addition, the function adds a unique tag in the From header. * * Once a transmit data is created, the reference counter is initialized to 1. * * @param endpt Endpoint instance. * @param method SIP Method. * @param target Target URI. * @param from URL to put in From header. * @param to URL to put in To header. * @param contact URL to put in Contact header. * @param call_id Optional Call-ID (put NULL to generate unique Call-ID). * @param cseq Optional CSeq (put -1 to generate random CSeq). * @param text Optional text body (put NULL to omit body). * @param p_tdata Pointer to receive the transmit data. * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t) pjsip_endpt_create_request( pjsip_endpoint *endpt, const pjsip_method *method, const pj_str_t *target, const pj_str_t *from, const pj_str_t *to, const pj_str_t *contact, const pj_str_t *call_id, int cseq, const pj_str_t *text, pjsip_tx_data **p_tdata);/** * Create an independent request message from the specified headers. This * function will clone the headers and put them in the request. * * This function adds the following headers in the request: * - From, To, Call-ID, and CSeq, * - Contact header, if contact is specified. * - A blank Via header. * - Additional request headers (such as Max-Forwards) which are copied * from endpoint configuration. * * In addition, the function adds a unique tag in the From header. * * Once a transmit data is created, the reference counter is initialized to 1. * * @param endpt Endpoint instance. * @param method SIP Method. * @param target Target URI. * @param from URL to put in From header. * @param to URL to put in To header. * @param contact URL to put in Contact header. * @param call_id Optional Call-ID (put NULL to generate unique Call-ID). * @param cseq Optional CSeq (put -1 to generate random CSeq). * @param text Optional text body (put NULL to omit body). * @param p_tdata Pointer to receive the transmit data. * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t)pjsip_endpt_create_request_from_hdr( pjsip_endpoint *endpt, const pjsip_method *method, const pjsip_uri *target, const pjsip_from_hdr *from, const pjsip_to_hdr *to, const pjsip_contact_hdr *contact, const pjsip_cid_hdr *call_id, int cseq, const pj_str_t *text, pjsip_tx_data **p_tdata);/** * Construct a minimal response message for the received request. This function * will construct all the Via, Record-Route, Call-ID, From, To, CSeq, and * Call-ID headers from the request. * * Note: the txdata reference counter is set to ZERO!. * * @param endpt The endpoint. * @param rdata The request receive data. * @param st_code Status code to be put in the response. * @param st_text Optional status text, or NULL to get the default text. * @param p_tdata Pointer to receive the transmit data. * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t) pjsip_endpt_create_response( pjsip_endpoint *endpt, const pjsip_rx_data *rdata, int st_code, const pj_str_t *st_text, pjsip_tx_data **p_tdata);/** * Construct a full ACK request for the received non-2xx final response. * This utility function is normally called by the transaction to construct * an ACK request to 3xx-6xx final response. * The generation of ACK message for 2xx final response is different than * this one. * * @param endpt The endpoint. * @param tdata This contains the original INVITE request * @param rdata The final response. * @param ack The ACK request created. * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t) pjsip_endpt_create_ack( pjsip_endpoint *endpt, const pjsip_tx_data *tdata, const pjsip_rx_data *rdata, pjsip_tx_data **ack);/** * Construct CANCEL request for the previously sent request. * * @param endpt The endpoint. * @param tdata The transmit buffer for the request being cancelled. * @param p_tdata Pointer to receive the transmit data. * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t) pjsip_endpt_create_cancel( pjsip_endpoint *endpt, const pjsip_tx_data *tdata, pjsip_tx_data **p_tdata);/** * Find which destination to be used to send the request message, based * on the request URI and Route headers in the message. The procedure * used here follows the guidelines on sending the request in RFC 3261 * chapter 8.1.2. * * Note there was a change in the behavior of this function since version * 0.5.10.2. Previously this function may modify the request when strict * route is present (to update request URI and route-set). This is no * longer the case now, and this process is done in separate function * (see #pjsip_process_route_set()). * * @param tdata The transmit data containing the request message. * @param dest_info On return, it contains information about destination * host to contact, along with the preferable transport * type, if any. Caller will then normally proceed with * resolving this host with server resolution procedure * described in RFC 3263. * * @return PJ_SUCCESS, or the appropriate error code. * * @see pjsip_process_route_set */PJ_DECL(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata, pjsip_host_info *dest_info );/** * Process route-set found in the request and calculate destination to be * used to send the request message, based on the request URI and Route * headers in the message. The procedure used here follows the guidelines * on sending the request in RFC 3261 chapter 8.1.2. * * This function may modify the message (request line and Route headers), * if the Route information specifies strict routing and the request * URI in the message is different than the calculated target URI. In that * case, the target URI will be put as the request URI of the request and * current request URI will be put as the last entry of the Route headers. * * @param tdata The transmit data containing the request message. * @param dest_info On return, it contains information about destination * host to contact, along with the preferable transport * type, if any. Caller will then normally proceed with * resolving this host with server resolution procedure * described in RFC 3263. * * @return PJ_SUCCESS, or the appropriate error code. * * @see pjsip_get_request_addr */PJ_DECL(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata, pjsip_host_info *dest_info );/** * This structure holds the state of outgoing stateless request. */typedef struct pjsip_send_state{ /** Application token, which was specified when the function * #pjsip_endpt_send_request_stateless() is called. */ void *token; /** Endpoint instance. */ pjsip_endpoint *endpt; /** Transmit data buffer being sent. */ pjsip_tx_data *tdata; /** Server addresses resolved. */ pjsip_server_addresses addr; /** Current server address being tried. */ unsigned cur_addr; /** Current transport being used. */ pjsip_transport *cur_transport; /** The application callback which was specified when the function * #pjsip_endpt_send_request_stateless() was called. */ void (*app_cb)(struct pjsip_send_state*, pj_ssize_t sent, pj_bool_t *cont);} pjsip_send_state;/** * Send outgoing request statelessly The function will take care of which * destination and transport to use based on the information in the message, * taking care of URI in the request line and Route header. * * This function is different than #pjsip_transport_send() in that this * function adds/modify the Via header as necessary. * * @param endpt The endpoint instance. * @param tdata The transmit data to be sent. * @param token Arbitrary token to be given back on the callback. * @param cb Optional callback to notify transmission status (also * gives chance for application to discontinue retrying * sending to alternate address). * * @return PJ_SUCCESS, or the appropriate error code. */PJ_DECL(pj_status_t) pjsip_endpt_send_request_stateless( pjsip_endpoint *endpt, pjsip_tx_data *tdata, void *token, void (*cb)(pjsip_send_state*, pj_ssize_t sent, pj_bool_t *cont));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -