From 4dd5c0ffd46b464baa2dc89cd2f6b0273a35885c Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 14 May 2007 16:37:47 +0000 Subject: Ticket #272: the From parameter on_pager() callback contains Contact instead (thanks Nicholas Xu), and also allow non-text/plain IM messages git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/pjproject-0.5-stable@1271 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/pjsua_app.c | 5 +-- pjsip/src/pjsua-lib/pjsua_im.c | 69 +++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index e4b51de3..f509f6a3 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -1740,9 +1740,10 @@ static void on_pager(pjsua_call_id call_id, const pj_str_t *from, PJ_UNUSED_ARG(contact); PJ_UNUSED_ARG(mime_type); - PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s", + PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s (%.*s)", (int)from->slen, from->ptr, - (int)text->slen, text->ptr)); + (int)text->slen, text->ptr, + (int)mime_type->slen, mime_type->ptr)); } diff --git a/pjsip/src/pjsua-lib/pjsua_im.c b/pjsip/src/pjsua-lib/pjsua_im.c index aa56e348..561f15a1 100644 --- a/pjsip/src/pjsua-lib/pjsua_im.c +++ b/pjsip/src/pjsua-lib/pjsua_im.c @@ -72,6 +72,7 @@ static const pj_str_t STR_MIME_PLAIN = { "plain", 5 }; /* Check if content type is acceptable */ +#if 0 static pj_bool_t acceptable_message(const pjsip_media_type *mime) { return (pj_stricmp(&mime->type, &STR_MIME_TEXT)==0 && @@ -80,7 +81,7 @@ static pj_bool_t acceptable_message(const pjsip_media_type *mime) (pj_stricmp(&mime->type, &STR_MIME_APP)==0 && pj_stricmp(&mime->subtype, &STR_MIME_ISCOMPOSING)==0); } - +#endif /** * Create Accept header for MESSAGE. @@ -104,6 +105,8 @@ pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool) pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata, pjsip_accept_hdr **p_accept_hdr) { + /* Some UA sends text/html, so this check will break */ +#if 0 pjsip_ctype_hdr *ctype; pjsip_msg *msg; @@ -122,6 +125,10 @@ pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata, return PJ_FALSE; } +#else + PJ_UNUSED_ARG(rdata); + PJ_UNUSED_ARG(p_accept_hdr); +#endif return PJ_TRUE; } @@ -154,23 +161,9 @@ void pjsua_im_process_pager(int call_id, const pj_str_t *from, contact.slen = 0; } - - if (pj_stricmp(&body->content_type.type, &STR_MIME_TEXT)==0 && - pj_stricmp(&body->content_type.subtype, &STR_MIME_PLAIN)==0) + if (pj_stricmp(&body->content_type.type, &STR_MIME_APP)==0 && + pj_stricmp(&body->content_type.subtype, &STR_MIME_ISCOMPOSING)==0) { - const pj_str_t mime_text_plain = pj_str("text/plain"); - pj_str_t text_body; - - /* Save text body */ - text_body.ptr = rdata->msg_info.msg->body->data; - text_body.slen = rdata->msg_info.msg->body->len; - - if (pjsua_var.ua_cfg.cb.on_pager) { - (*pjsua_var.ua_cfg.cb.on_pager)(call_id, from, to, &contact, - &mime_text_plain, &text_body); - } - - } else { /* Expecting typing indication */ pj_status_t status; pj_bool_t is_typing; @@ -187,6 +180,33 @@ void pjsua_im_process_pager(int call_id, const pj_str_t *from, (*pjsua_var.ua_cfg.cb.on_typing)(call_id, from, to, &contact, is_typing); } + + } else { + pj_str_t mime_type; + char buf[256]; + pjsip_media_type *m; + pj_str_t text_body; + + /* Save text body */ + text_body.ptr = rdata->msg_info.msg->body->data; + text_body.slen = rdata->msg_info.msg->body->len; + + /* Get mime type */ + m = &rdata->msg_info.msg->body->content_type; + mime_type.ptr = buf; + mime_type.slen = pj_ansi_snprintf(buf, sizeof(buf), + "%.*s/%.*s", + (int)m->type.slen, + m->type.ptr, + (int)m->subtype.slen, + m->subtype.ptr); + if (mime_type.slen < 1) + mime_type.slen = 0; + + if (pjsua_var.ua_cfg.cb.on_pager) { + (*pjsua_var.ua_cfg.cb.on_pager)(call_id, from, to, &contact, + &mime_type, &text_body); + } } } @@ -199,7 +219,6 @@ static pj_bool_t im_on_rx_request(pjsip_rx_data *rdata) { pj_str_t from, to; pjsip_accept_hdr *accept_hdr; - pjsip_contact_hdr *contact_hdr; pjsip_msg *msg; pj_status_t status; @@ -241,17 +260,9 @@ static pj_bool_t im_on_rx_request(pjsip_rx_data *rdata) * not available, then use From header. */ from.ptr = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); - contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, - PJSIP_H_CONTACT, NULL); - if (contact_hdr) { - from.slen = pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, - contact_hdr->uri, - from.ptr, PJSIP_MAX_URL_SIZE); - } else { - from.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, - rdata->msg_info.from->uri, - from.ptr, PJSIP_MAX_URL_SIZE); - } + from.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, + rdata->msg_info.from->uri, + from.ptr, PJSIP_MAX_URL_SIZE); if (from.slen < 1) from = pj_str("<--URI is too long-->"); -- cgit v1.2.3