[asterisk-commits] mmichelson: branch mmichelson/caller_id r384671 - /team/mmichelson/caller_id/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 3 13:16:25 CDT 2013
Author: mmichelson
Date: Wed Apr 3 13:16:21 2013
New Revision: 384671
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384671
Log:
Change the way that P-Asserted-Identity and Remote-Party-ID headers are parsed.
Before, they were being parsed as strings and then run through a URI parser. This
will break down if there are any header parameters present. Now we parse the header
as a fromto header so that we have easy access to the URI and parameters. This
will come in handy once we start looking at privacy values in Remote-Party-ID headers.
Modified:
team/mmichelson/caller_id/res/res_sip_caller_id.c
Modified: team/mmichelson/caller_id/res/res_sip_caller_id.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip_caller_id.c?view=diff&rev=384671&r1=384670&r2=384671
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Wed Apr 3 13:16:21 2013
@@ -32,11 +32,12 @@
#include "asterisk/module.h"
#include "asterisk/callerid.h"
-static void set_id_from_nameaddr(pjsip_name_addr *id_name_addr, struct ast_party_id *id)
+static void set_id_from_hdr(pjsip_fromto_hdr *hdr, struct ast_party_id *id)
{
char cid_name[AST_CHANNEL_NAME];
char cid_num[AST_CHANNEL_NAME];
pjsip_sip_uri *uri;
+ pjsip_name_addr *id_name_addr = (pjsip_name_addr *) hdr->uri;
uri = pjsip_uri_get_uri(id_name_addr);
ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));
@@ -52,59 +53,76 @@
}
}
-static int get_id_from_header(pjsip_rx_data *rdata, const pj_str_t *header_name, struct ast_party_id *id)
-{
+static pjsip_fromto_hdr *get_id_header(pjsip_rx_data *rdata, const pj_str_t *header_name)
+{
+ static const pj_str_t from = { "From", 4 };
pjsip_generic_string_hdr *ident = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,
header_name, rdata->msg_info.msg->hdr.next);
+ pjsip_fromto_hdr *parsed_hdr;
+ int parsed_len;
pj_str_t header_content;
- pjsip_name_addr *id_name_addr;
if (!ident) {
- return -1;
+ return NULL;
}
pj_strdup_with_null(rdata->tp_info.pool, &header_content, &ident->hvalue);
- id_name_addr = (pjsip_name_addr *)pjsip_parse_uri(rdata->tp_info.pool,
- header_content.ptr, header_content.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
-
- if (!id_name_addr) {
- return -1;
- }
-
- set_id_from_nameaddr(id_name_addr, id);
+ parsed_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from, header_content.ptr,
+ pj_strlen(&header_content), &parsed_len);
+
+ if (!parsed_hdr) {
+ return NULL;
+ }
+
+ return parsed_hdr;
+}
+
+static int get_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)
+{
+ pj_str_t pai_str = { "P-Asserted-Identity", 19 };
+ pjsip_fromto_hdr *pai_hdr = get_id_header(rdata, &pai_str);
+ if (!pai_hdr) {
+ return -1;
+ }
+
+ set_id_from_hdr(pai_hdr, id);
if (!id->number.valid) {
return -1;
}
- return 0;
-}
-
-static int get_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)
-{
- pj_str_t pai_str = { "P-Asserted-Identity", 19 };
- return get_id_from_header(rdata, &pai_str, id);
+
+ return 0;
}
static int get_id_from_rpid(pjsip_rx_data *rdata, struct ast_party_id *id)
{
pj_str_t rpid_str = { "Remote-Party-ID", 15 };
- return get_id_from_header(rdata, &rpid_str, id);
+ pjsip_fromto_hdr *rpid_hdr = get_id_header(rdata, &rpid_str);
+ if (!rpid_hdr) {
+ return -1;
+ }
+
+ set_id_from_hdr(rpid_hdr, id);
+
+ if (!id->number.valid) {
+ return -1;
+ }
+
+ return 0;
}
static int get_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)
{
pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,
PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);
- pjsip_name_addr *id_name_addr;
if (!from) {
/* This had better not happen */
return -1;
}
- id_name_addr = (pjsip_name_addr *)from->uri;
- set_id_from_nameaddr(id_name_addr, id);
+ set_id_from_hdr(from, id);
if (!id->number.valid) {
return -1;
More information about the asterisk-commits
mailing list