Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 249060) +++ channels/chan_sip.c (working copy) @@ -12329,7 +12329,6 @@ static int get_destination(struct sip_pvt *p, struct sip_request *oreq) { char tmp[256] = "", *uri, *domain, *dummy = NULL; - char tmpf[256] = "", *from = NULL; struct sip_request *req; char *decoded_uri; @@ -12353,24 +12352,6 @@ ast_string_field_set(p, domain, domain); - /* Now find the From: caller ID and name */ - /* XXX Why is this done in get_destination? Isn't it already done? - Needs to be checked - */ - ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf)); - if (!ast_strlen_zero(tmpf)) { - from = get_in_brackets(tmpf); - if (parse_uri(from, "sip:,sips:", &from, NULL, &domain, NULL, NULL)) { - ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", from); - return -1; - } - - SIP_PEDANTIC_DECODE(from); - SIP_PEDANTIC_DECODE(domain); - - ast_string_field_set(p, fromdomain, domain); - } - if (!AST_LIST_EMPTY(&domain_list)) { char domain_context[AST_MAX_EXTENSION]; @@ -12405,7 +12386,7 @@ Since extensions.conf can have unescaped characters, try matching a decoded uri in addition to the non-decoded uri Return 0 if we have a matching extension */ - if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) || ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) || + if (ast_exists_extension(NULL, p->context, uri, 1, p->cid_num) || ast_exists_extension(NULL, p->context, decoded_uri, 1, p->cid_num) || !strcmp(decoded_uri, ast_pickup_ext())) { if (!oreq) ast_string_field_set(p, exten, decoded_uri); @@ -12415,7 +12396,7 @@ /* Return 1 for pickup extension or overlap dialling support (if we support it) */ if((ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) && - ast_canmatch_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from))) || + ast_canmatch_extension(NULL, p->context, decoded_uri, 1, p->cid_num)) || !strncmp(decoded_uri, ast_pickup_ext(), strlen(decoded_uri))) { return 1; } @@ -12423,6 +12404,70 @@ return -1; } +/*! \brief Find out who the call is from. + We use the from-header as a source. + \return 0 on success -1 on error. + +*/ + +static int get_source(struct sip_pvt *p, struct sip_request *req) { + + char from[256] = { 0, }; + char *dummy; /* dummy return value for parse_uri */ + char *domain; /* dummy return value for parse_uri */ + char *of; + char calleridname[50]; + + ast_copy_string(from, get_header(req, "From"), sizeof(from)); + /* XXX here tries to map the username for invite things */ + memset(calleridname, 0, sizeof(calleridname)); + + /* strip the display-name portion off the beginning of the FROM header. */ + if (!(of = (char *) get_calleridname(from, calleridname, sizeof(calleridname)))) { + ast_log(LOG_ERROR, "FROM header can not be parsed \n"); + return -1; + } + + if (calleridname[0]) + ast_string_field_set(p, cid_name, calleridname); + + of = get_in_brackets(of); + + /* save the URI part of the From header - for what it is worth */ + ast_string_field_set(p, from, of); + + /* ignore all fields but name */ + if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, NULL)) { + ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); + } + + SIP_PEDANTIC_DECODE(of); + SIP_PEDANTIC_DECODE(domain); + + ast_string_field_set(p, fromdomain, domain); + + if (ast_strlen_zero(of)) { + /* XXX note: the original code considered a missing @host + * as a username-only URI. The SIP RFC (19.1.1) says that + * this is wrong, and it should be considered as a domain-only URI. + * For backward compatibility, we keep this block, but it is + * really a mistake and should go away. + */ + of = domain; + } else { + char *tmp = ast_strdupa(of); + /* We need to be able to handle auth-headers looking like + + */ + tmp = strsep(&tmp, ";"); + if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) + ast_shrink_phone_number(tmp); + ast_string_field_set(p, cid_num, tmp); + } + return 0; +} + + /*! \brief Lock dialog lock and find matching pvt lock \return a reference, remember to release it when done */ @@ -13022,8 +13067,6 @@ struct sockaddr_in *sin, struct sip_peer **authpeer) { char from[256] = { 0, }; - char *dummy; /* dummy return value for parse_uri */ - char *domain; /* dummy return value for parse_uri */ char *of; enum check_auth_result res = AUTH_DONT_KNOW; char calleridname[50]; @@ -13031,19 +13074,6 @@ terminate_uri(uri2); /* trim extra stuff */ - ast_copy_string(from, get_header(req, "From"), sizeof(from)); - /* XXX here tries to map the username for invite things */ - memset(calleridname, 0, sizeof(calleridname)); - - /* strip the display-name portion off the beginning of the FROM header. */ - if (!(of = (char *) get_calleridname(from, calleridname, sizeof(calleridname)))) { - ast_log(LOG_ERROR, "FROM header can not be parsed \n"); - return res; - } - - if (calleridname[0]) - ast_string_field_set(p, cid_name, calleridname); - if (ast_strlen_zero(p->exten)) { char *t = uri2; if (!strncasecmp(t, "sip:", 4)) @@ -13059,38 +13089,6 @@ build_contact(p); } - of = get_in_brackets(of); - - /* save the URI part of the From header */ - ast_string_field_set(p, from, of); - - /* ignore all fields but name */ - if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, NULL)) { - ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); - } - - SIP_PEDANTIC_DECODE(of); - SIP_PEDANTIC_DECODE(domain); - - if (ast_strlen_zero(of)) { - /* XXX note: the original code considered a missing @host - * as a username-only URI. The SIP RFC (19.1.1) says that - * this is wrong, and it should be considered as a domain-only URI. - * For backward compatibility, we keep this block, but it is - * really a mistake and should go away. - */ - of = domain; - } else { - char *tmp = ast_strdupa(of); - /* We need to be able to handle auth-headers looking like - - */ - tmp = strsep(&tmp, ";"); - if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) - ast_shrink_phone_number(tmp); - ast_string_field_set(p, cid_num, tmp); - } - if (global_match_auth_username) { /* * XXX This is experimental code to grab the search key from the @@ -13109,6 +13107,9 @@ of = from; of = strsep(&of, "\""); } + } else { + ast_copy_string(from,p->cid_num,sizeof(from)); + of = from; } res = check_peer_ok(p, of, req, sipmethod, sin, @@ -18299,6 +18300,7 @@ return 0; } + get_source(p,req); /* get_destination no longer gets its own source information */ res = get_destination(p, req); build_contact(p); @@ -19151,6 +19153,8 @@ /* Handle authentication if this is our first invite */ struct ast_party_redirecting redirecting = {{0,},}; set_pvt_allowed_methods(p, req); + + get_source(p,req); /* check_user and get_destination no longer get their own source information */ res = check_user(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin); if (res == AUTH_CHALLENGE_SENT) { p->invitestate = INV_COMPLETED; /* Needs to restart in another INVITE transaction */ @@ -20424,6 +20428,7 @@ event = (char *) eventheader; /* XXX is this legal ? */ /* Handle authentication */ + get_source(p,req); /* check_user and get_destination no longer get their own source information */ res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, &authpeer); /* if an authentication response was sent, we are done here */ if (res == AUTH_CHALLENGE_SENT) /* authpeer = NULL here */