summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-02-02 21:15:34 +0000
committerBenny Prijono <bennylp@teluu.com>2006-02-02 21:15:34 +0000
commit692baba184ea0fd26ce98659d54bfa8d2c15452c (patch)
tree97f4f5db912704e985755a801294e56885cb1096 /pjsip
parentecb6949ce990a0ddf2a2e73a7113baae5253143c (diff)
Added pjsip_endpt_respond()
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@131 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/src/pjsip/sip_util.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index af02e994..8684f50a 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -1194,6 +1194,17 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond_stateless( pjsip_endpoint *endpt,
pjsip_response_addr res_addr;
pjsip_tx_data *tdata;
+ /* Verify arguments. */
+ PJ_ASSERT_RETURN(endpt && rdata, PJ_EINVAL);
+ PJ_ASSERT_RETURN(rdata->msg_info.msg->type == PJSIP_REQUEST_MSG,
+ PJSIP_ENOTREQUESTMSG);
+
+ /* Check that no UAS transaction has been created for this request.
+ * If UAS transaction has been created for this request, application
+ * MUST send the response statefully using that transaction.
+ */
+ PJ_ASSERT_RETURN(pjsip_rdata_get_tsx(rdata)==NULL, PJ_EINVALIDOP);
+
/* Create response message */
status = pjsip_endpt_create_response( endpt, rdata, st_code, st_text,
&tdata);
@@ -1232,6 +1243,72 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond_stateless( pjsip_endpoint *endpt,
return status;
}
+
+/*
+ * Send response statefully.
+ */
+PJ_DEF(pj_status_t) pjsip_endpt_respond( pjsip_endpoint *endpt,
+ pjsip_module *tsx_user,
+ pjsip_rx_data *rdata,
+ int st_code,
+ const pj_str_t *st_text,
+ const pjsip_hdr *hdr_list,
+ const pjsip_msg_body *body,
+ pjsip_transaction **p_tsx )
+{
+ pj_status_t status;
+ pjsip_tx_data *tdata;
+ pjsip_transaction *tsx;
+
+ /* Validate arguments. */
+ PJ_ASSERT_RETURN(endpt && rdata, PJ_EINVAL);
+
+ if (p_tsx) *p_tsx = NULL;
+
+ /* Create response message */
+ status = pjsip_endpt_create_response( endpt, rdata, st_code, st_text,
+ &tdata);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ /* Add the message headers, if any */
+ if (hdr_list) {
+ const pjsip_hdr *hdr = hdr_list->next;
+ while (hdr != hdr_list) {
+ pjsip_msg_add_hdr( tdata->msg, pjsip_hdr_clone(tdata->pool, hdr) );
+ hdr = hdr->next;
+ }
+ }
+
+ /* Add the message body, if any. */
+ if (body) {
+ tdata->msg->body = pj_pool_alloc(tdata->pool, sizeof(pjsip_msg_body));
+ status = pjsip_msg_body_clone( tdata->pool, tdata->msg->body, body );
+ if (status != PJ_SUCCESS) {
+ pjsip_tx_data_dec_ref(tdata);
+ return status;
+ }
+ }
+
+ /* Create UAS transaction. */
+ status = pjsip_tsx_create_uas(tsx_user, rdata, &tsx);
+ if (status != PJ_SUCCESS) {
+ pjsip_tx_data_dec_ref(tdata);
+ return status;
+ }
+
+ /* Send the message. */
+ status = pjsip_tsx_send_msg(tsx, tdata);
+ if (status != PJ_SUCCESS) {
+ pjsip_tx_data_dec_ref(tdata);
+ } else {
+ *p_tsx = tsx;
+ }
+
+ return status;
+}
+
+
/*
* Get the event string from the event ID.
*/