diff --git a/apps/sbc/SBC.cpp b/apps/sbc/SBC.cpp index c993e528..bd578cfb 100644 --- a/apps/sbc/SBC.cpp +++ b/apps/sbc/SBC.cpp @@ -32,8 +32,6 @@ SBC - feature-wishlist - call distribution - select profile on monitoring in-mem DB record - fallback profile -- add headers -- online profile reload */ #include "SBC.h" @@ -427,6 +425,22 @@ void SBCDialog::onInvite(const AmSipRequest& req) inplaceHeaderFilter(invite_req.hdrs, call_profile.headerfilter_list, call_profile.headerfilter); + + if (!call_profile.append_headers.empty()) { + string append_headers = replaceParameters(call_profile.append_headers, + "append_headers", REPLACE_VALS); + if (append_headers.size()>2) { + if (append_headers[append_headers.size()-2] != '\r' || + append_headers[append_headers.size()-1] != '\n') { + while ((append_headers[append_headers.size()-1] == '\r') || + (append_headers[append_headers.size()-1] == '\n')) + append_headers.erase(append_headers.size()-1); + append_headers += "\r\n"; + } + invite_req.hdrs+=append_headers; + } + } + if (call_profile.auth_enabled) { call_profile.auth_credentials.user = replaceParameters(call_profile.auth_credentials.user, "auth_user", REPLACE_VALS); diff --git a/apps/sbc/SBCCallProfile.cpp b/apps/sbc/SBCCallProfile.cpp index 34bc57e1..5f02442f 100644 --- a/apps/sbc/SBCCallProfile.cpp +++ b/apps/sbc/SBCCallProfile.cpp @@ -167,6 +167,9 @@ bool SBCCallProfile::readFromConfiguration(const string& name, reply_translations[from_code] = make_pair(to_code, to_reply.substr(s_pos)); } + // append_headers=P-Received-IP: $si\r\nP-Received-Port:$sp\r\n + append_headers = cfg.getParameter("append_headers"); + md5hash = ""; if (!cfg.getMD5(profile_file_name, md5hash)){ ERROR("calculating MD5 of file %s\n", profile_file_name.c_str()); @@ -217,6 +220,10 @@ bool SBCCallProfile::readFromConfiguration(const string& name, INFO("SBC: reply translation for %s\n", reply_trans_codes.c_str()); } + if (append_headers.size()) { + INFO("SBC: append headers '%s'\n", append_headers.c_str()); + } + return true; } @@ -315,6 +322,7 @@ string SBCCallProfile::print() const { res += "prepaid_acc_dest: " + reply_trans_codes +"\n"; } + res += "append_headers: " + append_headers + "\n"; res += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; return res; } diff --git a/apps/sbc/SBCCallProfile.h b/apps/sbc/SBCCallProfile.h index 01690d0a..353fa73b 100644 --- a/apps/sbc/SBCCallProfile.h +++ b/apps/sbc/SBCCallProfile.h @@ -83,6 +83,8 @@ struct SBCCallProfile { map > reply_translations; + string append_headers; + // todo: RTP forwarding mode // todo: RTP transcoding mode diff --git a/apps/sbc/etc/transparent.sbcprofile.conf b/apps/sbc/etc/transparent.sbcprofile.conf index e3f00e41..1db5f845 100644 --- a/apps/sbc/etc/transparent.sbcprofile.conf +++ b/apps/sbc/etc/transparent.sbcprofile.conf @@ -27,6 +27,9 @@ #sdp_filter=whitelist #sdpfilter_list=g729,g723,ilbc,speex,gsm,amr +## append extra headers +#append_headers="P-Source-IP: $si\r\nP-Source-Port: $sp\r\n" + ## reply translations # translate some 6xx class replies to 4xx class: #reply_translations="603=>488 Not acceptable here|600=>406 Not Acceptable" diff --git a/doc/Readme.sbc.txt b/doc/Readme.sbc.txt index 765a36bb..f63ef4f1 100644 --- a/doc/Readme.sbc.txt +++ b/doc/Readme.sbc.txt @@ -154,6 +154,9 @@ The patterns which can be used are the following: \\ -> \ \$ -> $ \* -> * + \r -> cr (e.g. use \r\n to separate different headers in append_headers) + \n -> lf + \t -> tab If a quotation mark (") is used, it needs to be escaped with a backslash in the sbc profile configuration file. @@ -208,6 +211,17 @@ set to transparent, the SDP is parsed and reconstructed (SDP sanity check). Codecs may be filtered out by their payload names in whitelist or blacklist modes. The payload names in the list are case-insensitive (PCMU==pcmu). +Adding headers +-------------- +Additional headers can be added to the outgoing initial INVITE by using the +append_headers call profile option. Here, several headers can be separated with +\r\n. All replacement patterns from above can be used. + +Examples: + append_headers="P-Received-IP: $Ri\r\nP-Received-Port: $Rp" + append_headers="P-Source-IP: $si\r\nP-Source-Port: $sp\r\n" + append_headers="P-Original-URI: $r" + Response code translations ----------------------- Response codes and reasons may be translated, e.g. if some 6xx class replies need @@ -322,6 +336,6 @@ x maximum call duration timer - call distribution - select profile on monitoring in-mem DB record - fallback profile -- add headers +x add headers - bridging between interfaces - rel1xx in non-transparent mode