[asterisk-commits] kharwell: branch group/pimp_my_sip r387574 - in /team/group/pimp_my_sip: chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 3 10:42:11 CDT 2013


Author: kharwell
Date: Fri May  3 10:42:05 2013
New Revision: 387574

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387574
Log:
SIP Messaging for new channel driver.

Adds messaging support to the new SIP work being done in Asterisk. For the most
part this replicates the existing messaging features found in chan_sip.  For
instance, this module supports both out of call and in-dialog MESSAGE requests,
sending an out of call MESSAGE request via the MessageSend application, and
exposes handled requests in the MESSAGE/MESSAGE_DATA functions just to name
a few.

(closes issue ASTERISK-21076)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2423/

Added:
    team/group/pimp_my_sip/res/res_sip_messaging.c
      - copied unchanged from r387573, team/kharwell/pimp_my_sip/res/res_sip_messaging.c
Modified:
    team/group/pimp_my_sip/channels/chan_gulp.c
    team/group/pimp_my_sip/res/res_sip.c

Modified: team/group/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=387574&r1=387573&r2=387574
==============================================================================
--- team/group/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/group/pimp_my_sip/channels/chan_gulp.c Fri May  3 10:42:05 2013
@@ -1164,9 +1164,66 @@
 	return session->channel;
 }
 
+struct sendtext_data {
+	struct ast_sip_session *session;
+	char text[0];
+};
+
+static void sendtext_data_destroy(void *obj)
+{
+	struct sendtext_data *data = obj;
+	ao2_ref(data->session, -1);
+}
+
+static struct sendtext_data* sendtext_data_create(struct ast_sip_session *session, const char *text)
+{
+	int size = strlen(text) + 1;
+	struct sendtext_data *data = ao2_alloc(sizeof(*data)+size, sendtext_data_destroy);
+
+	if (!data) {
+		return NULL;
+	}
+
+	data->session = session;
+	ao2_ref(data->session, +1);
+	ast_copy_string(data->text, text, size);
+	return data;
+}
+
+static int sendtext(void *obj)
+{
+	RAII_VAR(struct sendtext_data *, data, obj, ao2_cleanup);
+	pjsip_tx_data *tdata;
+
+	const struct ast_sip_body body = {
+		.type = "text",
+		.subtype = "plain",
+		.body_text = data->text
+	};
+
+	/* NOT ast_strlen_zero, because a zero-length message is specifically
+	 * allowed by RFC 3428 (See section 10, Examples) */
+	if (!data->text) {
+		return 0;
+	}
+
+	ast_sip_create_request("MESSAGE", data->session->inv_session->dlg, data->session->endpoint, NULL, &tdata);
+	ast_sip_add_body(tdata, &body);
+	ast_sip_send_request(tdata, data->session->inv_session->dlg, data->session->endpoint);
+
+	return 0;
+}
+
 /*! \brief Function called by core to send text on Gulp session */
 static int gulp_sendtext(struct ast_channel *ast, const char *text)
 {
+	struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+	struct sendtext_data *data = sendtext_data_create(pvt->session, text);
+
+	if (!data || ast_sip_push_task(pvt->session->serializer, sendtext, data)) {
+		ao2_ref(data, -1);
+		return -1;
+	}
 	return 0;
 }
 

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=387574&r1=387573&r2=387574
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Fri May  3 10:42:05 2013
@@ -392,6 +392,7 @@
 
 /* PJSIP doesn't know about the INFO method, so we have to define it ourselves */
 const pjsip_method pjsip_info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} };
+const pjsip_method pjsip_message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
 
 static struct {
 	const char *method;
@@ -407,6 +408,7 @@
 	{ "NOTIFY", &pjsip_notify_method },
 	{ "PUBLISH", &pjsip_publish_method },
 	{ "INFO", &pjsip_info_method },
+	{ "MESSAGE", &pjsip_message_method },
 };
 
 static const pjsip_method *get_pjsip_method(const char *method)




More information about the asterisk-commits mailing list