[asterisk-commits] mmichelson: branch group/pimp_my_sip r379088 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 14 17:42:22 CST 2013


Author: mmichelson
Date: Mon Jan 14 17:42:19 2013
New Revision: 379088

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379088
Log:
Complete the body manipulation functions for res_sip.


Modified:
    team/group/pimp_my_sip/res/res_sip.c

Modified: team/group/pimp_my_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.c?view=diff&rev=379088&r1=379087&r2=379088
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Mon Jan 14 17:42:19 2013
@@ -287,13 +287,36 @@
 
 int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
 {
-	/* XXX Stub */
-	return 0;
+	pj_str_t hdr_name;
+	pj_str_t hdr_value;
+	pjsip_generic_string_hdr *hdr;
+	
+	pj_cstr(&hdr_name, name);
+	pj_cstr(&hdr_value, value);
+
+	hdr = pjsip_generic_string_hdr_create(tdata->pool, &hdr_name, &hdr_value);
+
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hdr);
+	return 0;
+}
+
+static pjsip_msg_body *ast_body_to_pjsip_body(pj_pool_t *pool, const struct ast_sip_body *body)
+{
+	pj_str_t type;
+	pj_str_t subtype;
+	pj_str_t body_text;
+
+	pj_cstr(&type, body->type);
+	pj_cstr(&subtype, body->subtype);
+	pj_cstr(&body_text, body->body_text);
+	
+	return pjsip_msg_body_create(pool, &type, &subtype, &body_text);
 }
 
 int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
 {
-	/* XXX stub */
+	pjsip_msg_body *pjsip_body = ast_body_to_pjsip_body(tdata->pool, body);
+	tdata->msg->body = pjsip_body;
 	return 0;
 }
 
@@ -304,16 +327,8 @@
 	pjsip_msg_body *body = pjsip_multipart_create(tdata->pool, NULL, NULL);
 
 	for (i = 0; i < num_bodies; ++i) {
-		pj_str_t type;
-		pj_str_t subtype;
-		pj_str_t body_text;
 		pjsip_multipart_part *part = pjsip_multipart_create_part(tdata->pool);
-
-		pj_cstr(&type, bodies[i]->type);
-		pj_cstr(&subtype, bodies[i]->subtype);
-		pj_cstr(&body_text, bodies[i]->body_text);
-
-		part->body = pjsip_msg_body_create(tdata->pool, &type, &subtype, &body_text);
+		part->body = ast_body_to_pjsip_body(tdata->pool, bodies[i]);
 		pjsip_multipart_add_part(tdata->pool, body, part);
 	}
 
@@ -323,7 +338,15 @@
 
 int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text)
 {
-	/* XXX stub */
+	size_t combined_size = strlen(body_text) + tdata->msg->body->len;
+	struct ast_str *body_buffer = ast_str_alloca(combined_size);
+
+	ast_str_set(&body_buffer, 0, "%.*s%s", (int) tdata->msg->body->len, (char *) tdata->msg->body->data, body_text);
+
+	tdata->msg->body->data = pj_pool_alloc(tdata->pool, combined_size);
+	pj_memcpy(tdata->msg->body->data, ast_str_buffer(body_buffer), combined_size);
+	tdata->msg->body->len = combined_size;
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list