Would be nicer not to forward all headers inline, that results in a
message easy to read (especially on mobile devices) and therefore faster
to answer.
You use subst over contact and set contact allias, which both append
values there, deleting same old content. Note that any change to sip
message is not applied immediately, but kept as a diff operation. You
need to use msg_apply_changes() after each change that you need to be
visible immediately -- read the readme of textopsx for proper usage of
this function.
Cheers,
Daniel
On 12/08/14 17:22, Alex Villacís Lasso wrote:
-------- Mensaje original --------
Return-Path: <sr-users-bounces(a)lists.sip-router.org>
Delivered-To: <a_villacis(a)palosanto.com>
Received: from
palosanto.com by
mail.palosanto.com (Dovecot) with
LMTP id o9JTLusS6VNAYAAA3RMWGw for <a_villacis(a)palosanto.com>om>; Mon, 11
Aug 2014 14:02:20 -0500
Received: from localhost (
mail.palosanto.com [127.0.0.1]) by
palosanto.com (Postfix) with ESMTP id DB61213C026F for
<a_villacis(a)palosanto.com>om>; Mon, 11 Aug 2014 14:02:20 -0500 (ECT)
X-Virus-Scanned: Debian amavisd-new at
mail.palosanto.com
X-Spam-Flag: NO
X-Spam-Score: -2.159
X-Spam-Level:
X-Spam-Status: No, score=-2.159 tagged_above=-1000 required=6.31
tests=[AWL=-0.259, BAYES_00=-1.9] autolearn=ham
Received: from
palosanto.com ([127.0.0.1]) by localhost
(
mail.palosanto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
id i5aRnN4kNPTq for <a_villacis(a)palosanto.com>om>; Mon, 11 Aug 2014
14:02:17 -0500 (ECT)
Received: from
www.kamailio.org (
main.kamailio.org [193.22.119.66])
by
palosanto.com (Postfix) with ESMTPS id AAB2813C0276 for
<a_villacis(a)palosanto.com>om>; Mon, 11 Aug 2014 14:02:16 -0500 (ECT)
Received: from localhost ([127.0.0.1]
helo=main.kamailio.org
ident=list) by
www.kamailio.org with esmtp (Exim 4.72) (envelope-from
<sr-users-bounces(a)lists.sip-router.org>) id 1XGurq-00065q-JJ; Mon, 11
Aug 2014 21:02:50 +0200
Received: from
lab2.palosanto.com ([201.234.196.173]
helo=palosanto.com) by
www.kamailio.org with esmtp (Exim 4.72)
(envelope-from <a_villacis(a)palosanto.com>) id 1XGuro-000654-FM for
sr-users(a)lists.sip-router.org; Mon, 11 Aug 2014 21:02:48 +0200
Received: from localhost (
mail.palosanto.com [127.0.0.1]) by
palosanto.com (Postfix) with ESMTP id D745713C026F for
<sr-users(a)lists.sip-router.org>rg>; Mon, 11 Aug 2014 14:02:04 -0500 (ECT)
X-Virus-Scanned: Debian amavisd-new at
mail.palosanto.com
Received: from
palosanto.com ([127.0.0.1]) by localhost
(
mail.palosanto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
id 6B6_a4ssmARw for <sr-users(a)lists.sip-router.org>rg>; Mon, 11 Aug 2014
14:02:02 -0500 (ECT)
Received: from
avillacis.palosanto.com (
avillacis.palosanto.com
[192.168.3.2]) by
palosanto.com (Postfix) with ESMTPSA id 8EBDA13C0286
for <sr-users(a)lists.sip-router.org>rg>; Mon, 11 Aug 2014 14:01:33 -0500
(ECT)
Message-ID: <53E91331.50104(a)palosanto.com>
Date: Mon, 11 Aug 2014 14:02:09 -0500
From: Alex Villacís Lasso <a_villacis(a)palosanto.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101
Thunderbird/24.7.0
MIME-Version: 1.0
To: sr-users(a)lists.sip-router.org
References: <53E54348.9090904(a)palosanto.com>
<53E8712A.2050407(a)gmail.com>
In-Reply-To: <53E8712A.2050407(a)gmail.com>
Subject: Re: [SR-Users] How do I make subst_hf() use variables in
search (not replacement)?
X-BeenThere: sr-users(a)lists.sip-router.org
X-Mailman-Version: 2.1.13
Precedence: list
Reply-To: Kamailio (SER) - Users Mailing List
<sr-users(a)lists.sip-router.org>
List-Id: "Kamailio \(SER\) - Users Mailing List"
<sr-users.lists.sip-router.org>
List-Unsubscribe:
<http://lists.sip-router.org/cgi-bin/mailman/options/sr-users>,
<mailto:sr-users-request@lists.sip-router.org?subject=unsubscribe>
List-Archive: <http://lists.sip-router.org/pipermail/sr-users>
List-Post: <mailto:sr-users@lists.sip-router.org>
List-Help: <mailto:sr-users-request@lists.sip-router.org?subject=help>
List-Subscribe:
<http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users>,
<mailto:sr-users-request@lists.sip-router.org?subject=subscribe>
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="windows-1252"; Format="flowed"
Sender: sr-users-bounces(a)lists.sip-router.org
Errors-To: sr-users-bounces(a)lists.sip-router.org
El 11/08/14 02:30, Daniel-Constantin Mierla escribió:
I haven't looked at the code, but probably
the function doesn't accept variable for the matching regular expression.
If the IP/port of asterisk are not changed, you can try:
#!substdef "/ASTERISKIP/127.0.0.1/"
#!substdef "/ASTERISKPORT/5080/"
asterisk.bindip = "ASTERISKIP" ...
asterisk.bindport = ASTERISKPORT ...
subst_hf("Contact", "/ASTERISKIP:ASTERISKPORT/$td/", "a");
Cheers,
Daniel
On 08/08/14 23:38, Alex Villacís Lasso wrote:
Consider the following snippet:
if (is_present_hf("Contact")) {
xlog("L_ALERT", "===== reply to SUBSCRIBE has
Contact:$ct\n");
xlog("L_ALERT", "===== want to replace with $td\n");
xlog("L_ALERT", "===== regexp to use is
/$sel(cfg_get.asterisk.bindip):$sel(cfg_get.asterisk.bindport)/$td/\n");
if (subst_hf("Contact", "/127.0.0.1:5080/$td/",
"a")) {
xlog("L_ALERT", "===== reply had Contact
modified\n");
}
}
If I use the hardcoded regexp "/127.0.0.1:5080/$td/", subst_hf() replaces the
Contact value correctly.
However, if I use
"/$sel(cfg_get.asterisk.bindip):$sel(cfg_get.asterisk.bindport)/$td/" (where
asterisk.bindip and asterisk.bindport are the supposed values 127.0.0.1 and 5080),
subst_hf() fails to replace the Contact value.
How do I make use of the existing configuration variables in order to substitute in the
Contact header?
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users Thanks for the
tip.
However, I also have an issue - subst_hf() does not seem to be working. Consider the
following route, of which the snippet quoted above is a part:
# manage incoming replies
onreply_route[MANAGE_REPLY] {
# run rtpproxy resolution
route(MHOMED_ELASTIX);
xdbg("incoming reply\n");
if(status=~"[12][0-9][0-9]")
route(NATMANAGE);
if (is_method("SUBSCRIBE") && route(FROMASTERISK)) {
#xlog("L_ALERT", "===== reply to SUBSCRIBE, coming from
asterisk, Call-ID is $ci\n");
$sht(pending_subscribe=>$ci) = 0;
if (is_present_hf("Contact")) {
xlog("L_ALERT", "===== reply to SUBSCRIBE has
Contact: $ct\n");
xlog("L_ALERT", "===== want to replace with
$td\n");
xlog("L_ALERT", "===== regexp to use is
/$sel(cfg_get.asterisk.bindip):$sel(cfg_get.asterisk.bindport)/$td/\n");
if (subst_hf("Contact",
"/127.0.0.1:5080/$td/", "a")) {
xlog("L_ALERT", "===== reply hadContact
modified\n");
}
}
}
# manage websocket reply
if (nat_uac_test(64)) {
# Do NAT traversal stuff for replies to a WebSocket connection
# - even if it is not behind a NAT!
# This won't be needed in the future if Kamailio and the
# WebSocket client support Outbound and Path.
add_contact_alias();
}
}
When I run this with debug=4, I get the following:
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [socket_info.c:583]:
grep_sock_info(): grep_sock_info - checking if host==us: 9==9 && [127.0.0.1] ==
[127.0.0.1]
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [dset.c:769]:
uri_add_rcv_alias(): encoded<sip:102@127.0.0.1:5080> =>
[sip:102@127.0.0.1:5080;alias=127.0.0.1~5080~1
]
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [select.c:429]:
run_select(): Calling SELECT 0x7f8e431a3d90
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [select.c:429]:
run_select(): Calling SELECT 0x7f8e43292ac0
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: htable
[ht_var.c:90]:pv_set_ht_cell(): set value for $ht(pending_subscribe=>6a2222bca4cc2be8)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: ALERT: <script>: ===== reply to
SUBSCRIBE has Contact:<sip:102@127.0.0.1:5080>;expires=3600
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: ALERT: <script>: ===== want to
replace with
pbx.villacis.com
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [select.c:429]:
run_select(): Calling SELECT 0x7f8e431a3d90
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [select.c:429]:
run_select(): Calling SELECT 0x7f8e43292ac0
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: ALERT: <script>: ===== regexp to use
is /127.0.0.1:5080/pbx.villacis.com/
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [re.c:454]:
subst_run(): subst_run: running. r=0
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [re.c:475]:
subst_run(): subst_run: matched (9, 14): [127.0.0.1:5080]
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: textops [textops.c:2285]:
subst_hf_f(): textops replacing at offset 849 [127.0.0.1:5080] with [
pbx.villacis.com]
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: textops [textops.c:2351]:
subst_hf_f(): lst was 0x7f8e432e4918
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: ALERT: <script>: ===== reply had
Contact modified
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: tm [t_reply.c:1304]:
t_should_relay_response(): ->>>>>>>>> T_code=0, new_code=200
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: tm [t_reply.c:1822]: relay_reply():
DEBUG: relay_reply: branch=0, save=0, relay=0 icode=0
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core>
[msg_translator.c:2009]: generate_res_buf_from_sip_res(): old size: 900, new size: 813
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core>
[msg_translator.c:2027]: generate_res_buf_from_sip_res(): copied size: orig:863, new: 776,
rest: 37 msg=#012SIP/2.0 200 OK#015#012Via: SIP/2.0/UDP
192.168.2.100:5060;rport=5060;branch=z9hG4bK036380ac70257f0f5#015#012Record-Route:
<sip:127.0.0.1;r2=on;lr=on;ftag=239adbead7;vsf=cBoZSlANEgEdDBcAFx8lMBIaVlgfBQANAgoaXU0MAi0xMjcuMC4wLjE6NTA4MA--;nat=yes>#015#012Record-Route:
<sip:192.168.2.18;r2=on;lr=on;ftag=239adbead7;vsf=cBoZSlANEgEdDBcAFx8lMBIaVlgfBQANAgoaXU0MAi0xMjcuMC4wLjE6NTA4MA--;nat=yes>#015#012From:
"jgutierrez"<sip:jgutierrez@pbx.villacis.com>;tag=239adbead7#015#012To:
""
<sip:102@pbx.villacis.com>;tag=as2e48d5d6#015#012Call-ID:
6a2222bca4cc2be8#015#012CSeq: 22329 SUBSCRIBE#015#012Server: Asterisk PBX
11.11.0#015#012Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO,
PUBLISH, MESSAGE#015#012Supported:
replaces, timer#015#012Expires:
3600#015#012Contact:<sip:102@127.0.0.1:5080;alias=127.0.0.1~5080~1pbx.villacis.com>;expires=3600#015#012Content-Length:
0#015#012#015#012
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [mem/shm_mem.c:111]:
_shm_resize(): WARNING:vqm_resize: resize(0) called
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: tm [t_reply.c:1663]:
cleanup_uac_timers(): DEBUG: cleanup_uac_timers: RETR/FR timers reset
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [usr_avp.c:644]:
destroy_avp_list(): DEBUG:destroy_avp_list: destroying list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [xavp.c:448]:
xavp_destroy_list(): destroying xavp list (nil)
Aug 11 12:52:53 elx3 /usr/sbin/kamailio[2971]: DEBUG: <core> [receive.c:296]:
receive_msg(): receive_msg: cleaning up
Apparently the search matched, and the replace was made. However, the replacement is
incorrect:
Contact:<sip:102@127.0.0.1:5080;alias=127.0.0.1~5080~1pbx.villacis.com>;expires=3600
What I going on? Is the regexp incorrect? What I expected for the Contact header is
this:
Contact:<sip:102@pbx.villacis.com>;expires=3600
or this:
Contact:<sip:102@pbx.villacis.com;alias=127.0.0.1~5080~1>;expires=3600
...although I am not sure whether the latter is a valid header, but at least it would do
something expected.
The documentation
(
http://www.kamailio.org/docs/modules/4.1.x/modules/textops.html#idp1655472) says the
regexp is perl-style, and a sample running with perl shows the regexp to work correctly
and to do what I want. I made a mistake when I mentioned that subst_hf() works correctly
with the hardcoded regexp. What was really happening is that it does get accepted as a
valid configuration, but displays unexpected behavior.
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users(a)lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users