diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-05-14 16:45:20 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-05-14 16:45:20 +0000 |
commit | 5406b158f07e67aab413b407d589920f2e120b4a (patch) | |
tree | ba4dcb386b3b87edd9bd70e852302f08ed159042 /pjsip/src/pjsua-lib/pjsua_im.c | |
parent | d56088c64c3def57ae8a9484814a9951475ae260 (diff) |
Ticket #274: 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/trunk@1272 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsua-lib/pjsua_im.c')
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_im.c | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_im.c b/pjsip/src/pjsua-lib/pjsua_im.c index b22d6f8c..e059ac94 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; @@ -123,6 +126,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; } @@ -156,23 +163,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 = (char*) 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; @@ -189,6 +182,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); + } } } @@ -201,7 +221,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; @@ -242,19 +261,10 @@ static pj_bool_t im_on_rx_request(pjsip_rx_data *rdata) * Contact header contains the port number information. If this is * not available, then use From header. */ - from.ptr = (char*) pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); - contact_hdr = (pjsip_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.ptr = pj_pool_alloc(rdata->tp_info.pool, 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-->"); |