diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-04 23:54:04 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-04 23:54:04 +0000 |
commit | aaf3c789a512a88c7c62d18d743804bc7bea7c3f (patch) | |
tree | 2b0d11caee08ec505a1507179175729835abb3d8 /channels | |
parent | b509add2a22ecace5a854f3c9f6500008a1340af (diff) |
handle peer matching for subscriptions by name instead of IP address (issue #5103)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6723 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-x | channels/chan_sip.c | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index d287e1ae8..c1b01fccb 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -6830,10 +6830,12 @@ static int get_rpid_num(char *input,char *output, int maxlen) } -/*--- check_user: Check if matching user or peer is defined ---*/ +/*--- check_user_full: Check if matching user or peer is defined ---*/ +/* Match user on From: user name and peer on IP/port */ +/* This is used on first invite (not re-invites) and subscribe requests */ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, int reliable, struct sockaddr_in *sin, int ignore, char *mailbox, int mailboxlen) { - struct sip_user *user; + struct sip_user *user = NULL; struct sip_peer *peer; char *of, from[256], *c; char *rpid,rpid_num[50]; @@ -6857,6 +6859,8 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme memset(calleridname,0,sizeof(calleridname)); get_calleridname(from, calleridname, sizeof(calleridname)); + if (calleridname[0]) + ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name)); rpid = get_header(req, "Remote-Party-ID"); memset(rpid_num,0,sizeof(rpid_num)); @@ -6889,13 +6893,14 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme ast_copy_string(p->cid_num, of, sizeof(p->cid_num)); ast_shrink_phone_number(p->cid_num); } - if (*calleridname) - ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name)); if (ast_strlen_zero(of)) return 0; - user = find_user(of, 1); + + if (!mailbox) /* If it's a mailbox SUBSCRIBE, don't check users */ + user = find_user(of, 1); + /* Find user based on user name in the from header */ - if (!mailbox && user && ast_apply_ha(user->ha, sin)) { + if (user && ast_apply_ha(user->ha, sin)) { ast_copy_flags(p, user, SIP_TRUSTRPID | SIP_USECLIENTCODE | SIP_NAT | SIP_PROG_INBAND | SIP_OSPAUTH); /* copy channel vars */ for (v = user->chanvars ; v ; v = v->next) { @@ -6972,11 +6977,16 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipme if (!user) { /* If we didn't find a user match, check for peers */ - /* Look for peer based on the IP address we received data from */ - /* If peer is registered from this IP address or have this as a default - IP address, this call is from the peer - */ - peer = find_peer(NULL, &p->recv, 1); + if (sipmethod == SIP_SUBSCRIBE) + /* For subscribes, match on peer name only */ + peer = find_peer(of, NULL, 1); + else + /* Look for peer based on the IP address we received data from */ + /* If peer is registered from this IP address or have this as a default + IP address, this call is from the peer + */ + peer = find_peer(NULL, &p->recv, 1); + if (peer) { if (debug) ast_verbose("Found peer '%s'\n", peer->name); @@ -10521,11 +10531,20 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, ast_verbose("Ignoring this SUBSCRIBE request\n"); if (!p->lastinvite) { - char mailbox[256]=""; + char mailboxbuf[256]=""; int found = 0; + char *mailbox = NULL; + int mailboxsize = 0; + char *event = get_header(req, "Event"); /* Get Event package name */ + char *accept = get_header(req, "Accept"); + + if (!strcmp(event, "message-summary") && !strcmp(accept, "application/simple-message-summary")) { + mailbox = mailboxbuf; + mailboxsize = sizeof(mailboxbuf); + } /* Handle authentication if this is our first subscribe */ - res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, mailbox, sizeof(mailbox)); + res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, mailbox, mailboxsize); if (res) { if (res < 0) { ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From")); @@ -10548,8 +10567,6 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, transmit_response(p, "484 Address Incomplete", req); /* Overlap dialing on SUBSCRIBE?? */ ast_set_flag(p, SIP_NEEDDESTROY); } else { - char *event = get_header(req, "Event"); /* Get Event package name */ - char *accept = get_header(req, "Accept"); /* Initialize tag for new subscriptions */ if (ast_strlen_zero(p->tag)) |