[asterisk-commits] kharwell: branch kharwell/pimp_my_sip r382356 - /team/kharwell/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 1 16:11:00 CST 2013


Author: kharwell
Date: Fri Mar  1 16:10:57 2013
New Revision: 382356

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382356
Log:
incoming messages are now passed to the dialplan - work continues...

Modified:
    team/kharwell/pimp_my_sip/res/res_sip_messaging.c

Modified: team/kharwell/pimp_my_sip/res/res_sip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_my_sip/res/res_sip_messaging.c?view=diff&rev=382356&r1=382355&r2=382356
==============================================================================
--- team/kharwell/pimp_my_sip/res/res_sip_messaging.c (original)
+++ team/kharwell/pimp_my_sip/res/res_sip_messaging.c Fri Mar  1 16:10:57 2013
@@ -26,6 +26,7 @@
 #undef bzero
 #define bzero bzero
 
+/* #include "pjsip/sip_uri.h" */
 #include "pjsua-lib/pjsua.h"
 
 #include "asterisk/res_sip.h"
@@ -266,6 +267,91 @@
 /* 	return PJ_SUCCESS; */
 /* } */
 
+static pj_status_t send_response(pjsip_rx_data *rdata, int code);
+
+static int queue_msg(pjsip_rx_data *rdata)
+{
+	int res, i;
+	char buf[256];
+	pjsip_uri *uri;
+	char *field;
+
+	struct ast_sip_endpoint *endpt = ast_pjsip_rdata_get_endpoint(rdata);
+	struct ast_msg *msg = ast_msg_alloc();
+
+	if (!msg) {
+		send_response(rdata, 500);
+		return PJ_FALSE;
+	}
+
+	/* to header */
+	uri = pjsip_uri_get_uri(rdata->msg_info.to->uri);
+	pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, buf, sizeof(buf)-1);
+	res = ast_msg_set_to(msg, "%s", buf);
+
+	/* from header */
+	uri = pjsip_uri_get_uri(rdata->msg_info.from->uri);
+	pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, buf, sizeof(buf)-1);
+	res |= ast_msg_set_from(msg, "%s", buf);
+
+	/* contact header */
+	field = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+	res |= ast_msg_set_var(msg, "SIP_FULLCONTACT", field);
+
+	/* receive address */
+	field = pj_sockaddr_print(&rdata->pkt_info.src_addr, buf, sizeof(buf)-1, 1);
+	res |= ast_msg_set_var(msg, "SIP_RECVADDR", field);
+
+	/* body - remove any trailing line feeds */
+	rdata->msg_info.msg->body->print_body(rdata->msg_info.msg->body, buf, sizeof(buf)-1);
+	for (i = strlen(buf); i > 0; --i) {
+		if (buf[i] != '\n') {
+			buf[i] = '\0';
+			break;
+		}
+	}
+	res |= ast_msg_set_body(msg, "%s", buf);
+
+	/* extension */
+	/* uri = rdata->msg_info.msg->line.req.uri; */
+	/* pjsip_sip_uri *sip_ruri; */
+	/* if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) { */
+	/* 	return SIP_GET_DEST_UNSUPPORTED_URI; */
+	/* } */
+	/* sip_ruri = pjsip_uri_get_uri(ruri); */
+	/* ast_copy_pj_str(session->exten, &sip_ruri->user, sizeof(session->exten)); */
+	/* if (ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) { */
+	/* 	return SIP_GET_DEST_EXTEN_FOUND; */
+	/* } */
+
+	/* context */
+	res |= ast_msg_set_context(msg, "%s", endpt->context);	
+
+	if (res) {
+		ast_msg_destroy(msg);
+		send_response(rdata, 500);
+		return PJ_FALSE;
+	}
+
+	ast_msg_queue(msg);
+	return PJ_TRUE;
+
+	/* if (!ast_strlen_zero(p->peername)) { */
+	/* 	res |= ast_msg_set_var(msg, "SIP_PEERNAME", p->peername); */
+	/* } */
+
+	/* res |= ast_msg_set_exten(msg, "%s", p->exten); */
+	/* res |= set_message_vars_from_req(msg, req); */
+
+	/* if (res) { */
+	/* 	ast_msg_destroy(msg); */
+	/* 	transmit_response(p, "500 Internal Server Error", req); */
+	/* } else { */
+	/* 	ast_msg_queue(msg); */
+	/* 	transmit_response(p, "202 Accepted", req); */
+	/* } */
+}
+
 static pj_status_t send_response(pjsip_rx_data *rdata, int code)
 {
 	pjsip_tx_data *tdata;
@@ -294,7 +380,6 @@
 			ast_log(LOG_ERROR, "Unable to get response address (%d)", status);
 			return status;
 		}
-
 		status = pjsip_endpt_send_response(endpt, &res_addr, tdata, NULL, NULL);
 	}
 
@@ -312,7 +397,14 @@
 		return PJ_FALSE;
 	}
 
-	return send_response(rdata, 202);
+	/* if (pj_strcmp2(rdata->msg_info.msg->body.content_type.type, "text") || */
+	/*     pj_strcmp2(rdata->msg_info.msg->body.content_type.subtype, "plain")) { */
+	/* 	    send_response(rdata, 415); */
+	if (queue_msg(rdata)) {
+		send_response(rdata, 202);
+	}
+
+	return PJ_TRUE;
 }
 
 /* static pj_bool_t module_on_rx_response(pjsip_rx_data *rdata) */
@@ -344,8 +436,6 @@
 
 static int load_module(void)
 {
-	/* const pj_str_t TAG = { "MESSAGE", 7 }; */
-
 	if (ast_sip_register_service(&messaging_module) != PJ_SUCCESS) {
 		return AST_MODULE_LOAD_FAILURE;
 	}




More information about the asterisk-commits mailing list