Index: /trunk/channels/chan_sip.c =================================================================== --- /trunk/channels/chan_sip.c (revision 358575) +++ /trunk/channels/chan_sip.c (working copy) @@ -11224,7 +11224,6 @@ const char *fromdomain; const char *privacy = NULL; const char *screen = NULL; - const char *anonymous_string = "\"Anonymous\" "; if (!ast_test_flag(&p->flags[0], SIP_SENDRPID)) { return 0; @@ -11249,13 +11248,19 @@ lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), ast_uri_sip_user); if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) { - if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { - ast_str_set(&tmp, -1, "%s", anonymous_string); - } else { + if (ast_test_flag(&p->flags[1], SIP_PAGE2_PEER_TRUSTED)) { + /* We trust this peer so always send PAI */ ast_str_set(&tmp, -1, "\"%s\" ", lid_name, lid_num, fromdomain); + add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp)); + if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { + add_header(req, "Privacy", "id"); + } + } else if ((lid_pres & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) { + ast_str_set(&tmp, -1, "\"%s\" ", lid_name, lid_num, fromdomain); + add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp)); } - add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp)); - } else { + } else if ((ast_test_flag(&p->flags[1], SIP_PAGE2_PEER_TRUSTED)) || ((lid_pres & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED)) { + /*We hide RPID if presentation is prohibited and peer is untrusted */ ast_str_set(&tmp, -1, "\"%s\" ;party=%s", lid_name, lid_num, fromdomain, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "calling" : "called"); switch (lid_pres) { @@ -11294,7 +11299,6 @@ if (!ast_strlen_zero(privacy) && !ast_strlen_zero(screen)) { ast_str_append(&tmp, -1, ";privacy=%s;screen=%s", privacy, screen); } - add_header(req, "Remote-Party-ID", ast_str_buffer(tmp)); } return 0; @@ -12389,7 +12393,12 @@ * their callerid restricted */ l = CALLERID_UNKNOWN; n = l; - d = FROMDOMAIN_INVALID; + if ((!ast_strlen_zero(p->fromuser)) && (ast_test_flag(&p->flags[0], SIP_SENDRPID))) { + /* If RPID is enabled and fromuser is set it is used for authentication/recognition of the peer on the other side so set the proper domain also */ + d = p->fromdomain; + } else { + d = FROMDOMAIN_INVALID; + } } } @@ -18236,6 +18245,7 @@ ast_cli(fd, " Ign SDP ver : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_IGNORESDPVERSION))); ast_cli(fd, " Trust RPID : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_TRUSTRPID))); ast_cli(fd, " Send RPID : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_SENDRPID))); + ast_cli(fd, " Trust Peer : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_PEER_TRUSTED))); ast_cli(fd, " Subscriptions: %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); ast_cli(fd, " Overlap dial : %s\n", allowoverlap2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP))); if (peer->outboundproxy) @@ -27800,7 +27810,6 @@ static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v) { int res = 1; - if (!strcasecmp(v->name, "trustrpid")) { ast_set_flag(&mask[0], SIP_TRUSTRPID); ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID); @@ -27808,7 +27817,7 @@ ast_set_flag(&mask[0], SIP_SENDRPID); if (!strcasecmp(v->value, "pai")) { ast_set_flag(&flags[0], SIP_SENDRPID_PAI); - } else if (!strcasecmp(v->value, "rpid")) { + } else if (!strcasecmp(v->value, "rpid")) { ast_set_flag(&flags[0], SIP_SENDRPID_RPID); } else if (ast_true(v->value)) { ast_set_flag(&flags[0], SIP_SENDRPID_RPID); @@ -27819,6 +27828,9 @@ } else if (!strcasecmp(v->name, "rpid_immediate")) { ast_set_flag(&mask[1], SIP_PAGE2_RPID_IMMEDIATE); ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RPID_IMMEDIATE); + } else if (!strcasecmp(v->name, "trustpeer")) { + ast_set_flag(&mask[1], SIP_PAGE2_PEER_TRUSTED); + ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_PEER_TRUSTED); } else if (!strcasecmp(v->name, "g726nonstandard")) { ast_set_flag(&mask[0], SIP_G726_NONSTANDARD); ast_set2_flag(&flags[0], ast_true(v->value), SIP_G726_NONSTANDARD); Index: /trunk/channels/sip/include/sip.h =================================================================== --- /trunk/channels/sip/include/sip.h (revision 358575) +++ /trunk/channels/sip/include/sip.h (working copy) @@ -352,6 +352,7 @@ #define SIP_PAGE2_VIDEOSUPPORT_ALWAYS (1 << 27) /*!< DP: Always set up video, even if endpoints don't support it */ #define SIP_PAGE2_HAVEPEERCONTEXT (1 << 28) /*< Are we associated with a configured peer context? */ #define SIP_PAGE2_USE_SRTP (1 << 29) /*!< DP: Whether we should offer (only) SRTP */ +#define SIP_PAGE2_PEER_TRUSTED (1 << 30) /*!< P: Wheter we trust the peer */ #define SIP_PAGE2_FLAGS_TO_COPY \ (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \ @@ -359,7 +360,7 @@ SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \ SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | SIP_PAGE2_PREFERRED_CODEC | \ SIP_PAGE2_RPID_IMMEDIATE | SIP_PAGE2_RPID_UPDATE | SIP_PAGE2_SYMMETRICRTP |\ - SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP) + SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP | SIP_PAGE2_PEER_TRUSTED) #define SIP_PAGE3_SNOM_AOC (1 << 0) /*!< DPG: Allow snom aoc messages */ Index: /trunk/configs/sip.conf.sample =================================================================== --- /trunk/configs/sip.conf.sample (revision 358608) +++ /trunk/configs/sip.conf.sample (working copy) @@ -344,8 +344,9 @@ ; transmit such UPDATE messages to it, then you must enable this option. ; Otherwise, we will have to wait until we can send a reinvite to ; transmit the information. -;prematuremedia=no ; Some ISDN links send empty media frames before - ; the call is in ringing or progress state. The SIP +;trustpeer = no ; If we should trus peer and send privacy information +;prematuremedia=no ; Some ISDN links send empty media frames before + ; the call is in ringing or progress state. The SIP ; channel will then send 183 indicating early media ; which will be empty - thus users get no ring signal. ; Setting this to "yes" will stop any media before we have @@ -1164,6 +1165,7 @@ ; disallow ; insecure ; trustrpid +; trustpeer ; progressinband ; promiscredir ; useclientcode