[asterisk-commits] mmichelson: branch group/pimp_my_sip r378842 - in /team/group/pimp_my_sip: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 17:13:56 CST 2013


Author: mmichelson
Date: Wed Jan  9 17:13:53 2013
New Revision: 378842

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378842
Log:
Start writing body code.

Oddly, I started with the one that I thought I'd do last. I've written
the multi-part body code. Next I need to write the simpler body function
and then write the appending code.


Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip.h
    team/group/pimp_my_sip/res/res_sip.c

Modified: team/group/pimp_my_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip.h?view=diff&rev=378842&r1=378841&r2=378842
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip.h Wed Jan  9 17:13:53 2013
@@ -242,6 +242,22 @@
 int ast_sip_push_task(struct ast_sip_work *work, int (*sip_task)(void *), void *task_data);
 
 /*!
+ * \brief SIP body description
+ *
+ * This contains a type and subtype that will be added as
+ * the "Content-Type" for the message as well as the body
+ * text.
+ */
+struct ast_sip_body {
+	/*! Type of the body, such as "application" */
+	const char *type;
+	/*! Subtype of the body, such as "sdp" */
+	const char *subtype;
+	/*! The text to go in the body */
+	const char *body_text;
+};
+
+/*!
  * \brief General purpose method for sending a SIP request
  *
  * Its typical use would be to send one-off messages such as an out of dialog
@@ -259,7 +275,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_send_request(const char *method, const char *body,
+int ast_sip_send_request(const char *method, const struct ast_sip_body *body,
 		struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
  
 /*!
@@ -381,7 +397,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_add_body(pjsip_tx_data *tdata, const char *body);
+int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body);
  
 /*!
  * \brief Add a multipart body to an outbound SIP message
@@ -394,7 +410,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_add_body_mutipart(pjsip_tx_data *tdata, const char *bodies[]);
+int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies);
  
 /*!
  * \brief Append body data to a SIP message
@@ -407,6 +423,6 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_append_body(pjsip_tx_data *tdata, const char *body);
+int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text);
 
 #endif /* _RES_SIP_H */

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=378842&r1=378841&r2=378842
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Wed Jan  9 17:13:53 2013
@@ -224,7 +224,7 @@
 	return NULL;
 }
 
-static int send_in_dialog_request(const pjsip_method *method, const char *body, struct pjsip_dialog *dlg)
+static int send_in_dialog_request(const pjsip_method *method, const struct ast_sip_body *body, struct pjsip_dialog *dlg)
 {
 	pj_status_t status;
 	pjsip_tx_data *tdata;
@@ -235,10 +235,8 @@
 		return -1;
 	}
 
-	if (!ast_strlen_zero(body)) {
-		/* XXX This requires a bit more thought. We may need to change the body argument
-		 * to a pjsip_msg_body or require a type/subtype argument
-		 */
+	if (body) {
+		ast_sip_add_body(tdata, body);
 	}
 
 	status = pjsip_dlg_send_request(dlg, tdata, -1, NULL);
@@ -250,7 +248,7 @@
 	return 0;
 }
 
-static int send_out_of_dialog_request(const pjsip_method *method, const char *body, struct ast_sip_endpoint *endpoint)
+static int send_out_of_dialog_request(const pjsip_method *method, const struct ast_sip_body *body, struct ast_sip_endpoint *endpoint)
 {
 	/*XXX Stub
 	 *
@@ -266,7 +264,7 @@
 	return 0;
 }
 
-int ast_sip_send_request(const char *method, const char *body, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
+int ast_sip_send_request(const char *method, const struct ast_sip_body *body, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
 {
 	const pjsip_method *pmethod = get_pjsip_method(method);
 
@@ -288,19 +286,37 @@
 	return 0;
 }
 
-int ast_sip_add_body(pjsip_tx_data *tdata, const char *body)
-{
-	/* XXX stub */
-	return 0;
-}
-
-int ast_sip_add_body_mutipart(pjsip_tx_data *tdata, const char *bodies[])
-{
-	/* XXX stub */
-	return 0;
-}
-
-int ast_sip_append_body(pjsip_tx_data *tdata, const char *body)
+int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
+{
+	/* XXX stub */
+	return 0;
+}
+
+int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies)
+{
+	int i;
+	/* NULL for type and subtype automatically creates "multipart/mixed" */
+	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);
+		pjsip_multipart_add_part(tdata->pool, body, part);
+	}
+
+	tdata->msg->body = body;
+	return 0;
+}
+
+int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text)
 {
 	/* XXX stub */
 	return 0;




More information about the asterisk-commits mailing list