[OpenSIPS-Users] New User - Trying to use variables instead of IP no's

Iñaki Baz Castillo ibc at aliax.net
Thu Jan 22 11:13:55 CET 2009


2009/1/22 Matti Zemack <Matti.Zemack at rtcfactory.com>:

> As a first attempt at my new job I thought I could try and rewrite the
> config-scripts used at my company so that one script easily could be used in
> both dev and all the different Live environments.
>
> Basically I could change a variable early in the opensips.cfg, and this
> would assign the correct IP's for me to be used later in the config.
>
>
> But I suspect I'm using Opensips variables in the wrong way…
>
> Example of original code:
>
>                              rewritehostport("10.0.1.100:5060");
>
> Which I try changing to:
>
>                              $var(GateWay_5060)="10.0.1.100:5060";
>
>                              rewritehostport("$var(GateWay_5060)");
>
> (This gives me runtime error:  ERROR:tm:uri2proxy: bad host name in URI
> <sip:$var(GateWay_5060)>)
>
> Actually also tried rewritehostport($var(GateWay_5060));  which also gives
> error: String expected…
>
>
>
> So basically, I suppose I'm asking;
>
> How can I cast variables in Opensips? Or should I do this some other,
> smarter, way?


Some functions (as "rewritehostport") don't allow pseudo-variables as
parameters.
I stringly recommend you to use M4 to compile your opensips.cfg file:



file /etc/opensips/opensips.cfg.m4:
---------------------------------------------
debug=3
log_stderror=no
log_facility=LOG_LOCAL7

fork=yes

...

listen=MY_IP:MY_PORT

...

    rewritehost("MEDIA_SERVER_IP:MEDIA_SERVER_PORT");

...
---------------------------------------------


file /etc/opensips/defines.m4 (at your home):
---------------------------------------------
divert(-1)

define(`MY_IP',						`192.168.10.23')
define(`MY_PORT',					`5060')
define(`MEDIA_SERVER_IP',		        `192.168.10.23')
define(`MEDIA_SERVER_PORT',		`5065')

divert(0)dnl
---------------------------------------------

file /etc/opensips/defines.m4 (at your office):
---------------------------------------------
divert(-1)

define(`MY_IP',						`123.123.123.123')
define(`MY_PORT',					`5060')
define(`MEDIA_SERVER_IP',		        `22.22.22.22')
define(`MEDIA_SERVER_PORT',		`5065')

divert(0)dnl
---------------------------------------------



Create a bash script:
/usr/local/bin/op-restart.sh:
----------------------------------------------
#!/bin/bash

DIR="/etc/opensips"

m4 $DIR/defines.m4 $DIR/opensips.cfg.m4 > $DIR/opensips.cfg

/etc/init.d/opensips restart
----------------------------------------------



So you just must change the /etc/opensips/opensips.cfg.m4 file and the
defines.m4 (this last file will be different depending on your
location).

-- 
Iñaki Baz Castillo
<ibc at aliax.net>



More information about the Users mailing list