[asterisk-commits] kharwell: branch kharwell/pimp_my_sip r384513 - in /team/kharwell/pimp_my_sip...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 1 18:14:25 CDT 2013
Author: kharwell
Date: Mon Apr 1 18:14:21 2013
New Revision: 384513
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384513
Log:
in dialog messaging fully working
Modified:
team/kharwell/pimp_my_sip/channels/chan_gulp.c
team/kharwell/pimp_my_sip/res/res_sip_messaging.c
team/kharwell/pimp_my_sip/res/res_sip_session.c
Modified: team/kharwell/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=384513&r1=384512&r2=384513
==============================================================================
--- team/kharwell/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_my_sip/channels/chan_gulp.c Mon Apr 1 18:14:21 2013
@@ -1002,28 +1002,61 @@
return session->channel;
}
+struct sendtext_data {
+ struct ast_sip_session *session;
+ const char *text;
+};
+
+static void sendtext_data_destroy(void *obj)
+{
+ struct sendtext_data *data = obj;
+
+ if (data->text) {
+ free((char*)data->text);
+ }
+}
+
+static struct sendtext_data* sendtext_data_create(struct ast_sip_session *session, const char *text)
+{
+ struct sendtext_data *data = ao2_alloc(sizeof(*data), sendtext_data_destroy);
+
+ if (data) {
+ data->session = session;
+ data->text = ast_strdup(text);
+ }
+ return data;
+}
+
+static int sendtext(void *obj)
+{
+ RAII_VAR(struct sendtext_data *, data, obj, ao2_cleanup);
+
+ 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;
+ }
+
+ if (ast_sip_send_request("MESSAGE", &body, data->session->inv_session->dlg, NULL) != PJ_SUCCESS) {
+ ast_log(LOG_ERROR, "Could not send text MESSAGE request\n");
+ }
+
+ 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 ast_sip_body body = {
- .type = "text",
- .subtype = "plain",
- .body_text = text
- };
-
- struct ast_sip_session *session = ast_channel_tech_pvt(ast);
-
- /* NOT ast_strlen_zero, because a zero-length message is specifically
- * allowed by RFC 3428 (See section 10, Examples) */
- if (!text) {
- return 0;
- }
-
- if (ast_sip_send_request("MESSAGE", &body, session->inv_session->dlg, NULL) != PJ_SUCCESS) {
- ast_log(LOG_ERROR, "Could not send text MESSAGE request\n");
- }
-
- return 0;
+ struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
+ struct sendtext_data *data = sendtext_data_create(pvt->session, text);
+
+ return ast_sip_push_task(NULL, sendtext, data);
}
/*! \brief Convert SIP hangup causes to Asterisk hangup causes */
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=384513&r1=384512&r2=384513
==============================================================================
--- team/kharwell/pimp_my_sip/res/res_sip_messaging.c (original)
+++ team/kharwell/pimp_my_sip/res/res_sip_messaging.c Mon Apr 1 18:14:21 2013
@@ -17,7 +17,9 @@
*/
/*** MODULEINFO
+ <depend>pjproject</depend>
<depend>res_sip</depend>
+ <depend>res_sip_session</depend>
<support_level>core</support_level>
***/
@@ -33,6 +35,8 @@
#include "asterisk/pbx.h"
#include "asterisk/res_sip.h"
#include "asterisk/res_sip_session.h"
+
+const pjsip_method pjsip_message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
static const int MAX_HDR_SIZE = 512;
static const int MAX_BODY_SIZE = 1024;
@@ -188,6 +192,33 @@
}
/*!
+ * \brief Prints the message body into the given char buffer.
+ *
+ * \details Copies body content from the received data into the given
+ * character buffer removing any extra carriage return/line feeds.
+ *
+ * \param rdata The SIP request
+ * \param buf Buffer to fill
+ * \param len The length of the buffer
+ */
+static int print_body(pjsip_rx_data *rdata, char *buf, int len)
+{
+ int res = rdata->msg_info.msg->body->print_body(
+ rdata->msg_info.msg->body, buf, len);
+
+ if (res < 0) {
+ return res;
+ }
+
+ /* remove any trailing carriage return/line feeds */
+ while (res > 0 && ((buf[--res] == '\r') || (buf[res] == '\n')));
+
+ buf[++res] = '\0';
+
+ return res;
+}
+
+/*!
* \brief Converts a pjsip_rx_data structure to an ast_msg structure.
*
* \details Attempts to fill in as much information as possible into the given
@@ -240,8 +271,7 @@
res |= ast_msg_set_var(msg, "SIP_RECVADDR", field);
/* body */
- if ((size = rdata->msg_info.msg->body->print_body(rdata->msg_info.msg->body, buf, sizeof(buf)-1)) > 0) {
- buf[size] = '\0';
+ if (print_body(rdata, buf, sizeof(buf) - 1) > 0) {
res |= ast_msg_set_body(msg, "%s", buf);
}
@@ -438,7 +468,7 @@
return PJ_TRUE;
}
-static int incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
+static int incoming_in_dialog_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
{
char buf[MAX_BODY_SIZE];
enum pjsip_status_code code;
@@ -452,7 +482,10 @@
return 0;
}
- rdata->msg_info.msg->body->print_body(rdata->msg_info.msg->body, buf, sizeof(buf)-1);
+ if (print_body(rdata, buf, sizeof(buf)-1) < 1) {
+ /* invalid body size */
+ return 0;
+ }
memset(&f, 0, sizeof(f));
f.frametype = AST_FRAME_TEXT;
@@ -466,14 +499,9 @@
return 0;
}
-/* static int outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata) */
-/* { */
-/* } */
-
static struct ast_sip_session_supplement messaging_supplement = {
.method = "MESSAGE",
- .incoming_request = incoming_request,
- /* .outgoing_request = outgoing_request */
+ .incoming_request = incoming_in_dialog_request
};
static pjsip_module messaging_module = {
Modified: team/kharwell/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_my_sip/res/res_sip_session.c?view=diff&rev=384513&r1=384512&r2=384513
==============================================================================
--- team/kharwell/pimp_my_sip/res/res_sip_session.c (original)
+++ team/kharwell/pimp_my_sip/res/res_sip_session.c Mon Apr 1 18:14:21 2013
@@ -1214,13 +1214,10 @@
*/
static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata)
{
+ static const pjsip_method pjsip_message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
+
pj_status_t handled = PJ_FALSE;
pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
-
- /* handle in dialog MESSAGE */
- if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_message_method) && dlg) {
- return PJ_TRUE;
- }
switch (rdata->msg_info.msg->line.req.method.id) {
case PJSIP_INVITE_METHOD:
@@ -1233,6 +1230,10 @@
break;
case PJSIP_OTHER_METHOD:
/* Area for INFO and REFER, possibly other methods */
+ if (dlg && pjsip_dlg_get_inv_session(dlg) &&
+ !pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_message_method)) {
+ return PJ_TRUE;
+ }
break;
default:
break;
@@ -1525,6 +1526,10 @@
ast_sip_session_send_request(session, tdata);
}
}
+ } else {
+ if (tsx->role == PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING) {
+ handle_incoming_request(session, e->body.tsx_state.src.rdata);
+ }
}
if (tsx->mod_data[session_module.id]) {
ast_sip_session_response_cb cb = tsx->mod_data[session_module.id];
More information about the asterisk-commits
mailing list