[OpenSIPS-Users] Include

Pauba, Kevin L KLPauba at west.com
Fri Jan 23 17:24:39 CET 2009


The example you provided is the method I used -- once you get used to the odd (but necessary) syntax, the syntax doesn't seem as bad.

Here's an example of some code that is similar to what I've done (although I have more than 50 macros defined in my current source).  The m4 source is copied to the SIP Proxy Server (in this example, a development host) and the following command is executed to generate the configuration:

$ m4 -DDEV config.m4 > config.cfg

--------------------------------

define(`ROUTE_MAIN', 0)
define(`_OPENSER_IP',`regexp(esyscmd(`hostname -i'),`\<.+\>',\&)')
define(`_OPENSER_PORT',`5060')
define(`_OPENSER_HOST',`regexp(esyscmd(`hostname -f'),`\<.+\>',\&)')

ifdef(`DEV',`
define(`OPENSER_NAME',`OPENSER (Development)')
define(`DEBUG_LEVEL',`3')
')

ifdef(`QA',`
define(`OPENSER_NAME',`OPENSER (Q`'A)')
define(`DEBUG_LEVEL',`3')
')

debug=DEBUG_LEVEL # -3 (L_ALERT) to 5 (L_DBG)
fork=no
log_stderror=no # do not print to stderr, if yes, syslog will be disabled
log_facility=LOG_LOCAL0

check_via=no    # (cmd. line: -v)
dns=no           # (cmd. line: -r)
rev_dns=no      # (cmd. line: -R)
listen=_OPENSER_IP
port=_OPENSER_PORT
children=4
alias="OPENSER_NAME"
alias="_OPENSER_HOST"

route[ROUTE_MAIN] {

	if (!mf_process_maxfwd_header("10")) {
      	sl_send_reply("483","Too Many Hops");
            return;
      };

      if (msg:len > max_len) {
      	sl_send_reply("513", "Message too big");
            return;
      };

      if (method == "INVITE" || method == "CANCEL") {
            #
            # Ensure a P-Charging-Vector header is present.
            #
            if (! is_present_hf("P-Charging-Vector")) {
            	$var(uuid) = $ci + $Ts + "_OPENSER_IP";
                  append_hf("P-Charging-Vector: icid-value=$(var(uuid){s.md5})\r\n");
            }

		ifdef(`DEV',`
			#
			# Special rules for use in development.
			#
			...
		')
		...
	}
	...
}


-----Original Message-----
From: Matti Zemack [mailto:Matti.Zemack at rtcfactory.com] 
Sent: Friday, January 23, 2009 2:33 AM
To: Pauba, Kevin L
Cc: users at lists.opensips.org
Subject: RE: [OpenSIPS-Users] Include

Thanks Kevin!


I've started using m4 as Iñaki showed me yesterday, basically for setting parameters on different systems. This I've already implemented and using "happily ever after". :-)

Is there a better way of using M4 for bigger pieces of code, than the example below:
divert(-1)
define(`ROUTE1',
`route[1] {
     xlog("L_NOTICE", "We are now in route1\n");
}
')
divert(0)dnl


Thanks,
Matti Zemack
Stockholm
Sweden

-----Original Message-----
From: Pauba, Kevin L [mailto:KLPauba at west.com] 
Sent: den 22 januari 2009 18:08
Not only the cleverest, I think it's the best!

I maintain the configuration for 12 SIP Proxies (using OpenSER) and I don't need 12 different configuration files.  A number of macros transform one m4 file into one of 12 different configuration files with the stroke of a short command line.

I'd be happy to help provide some help to get you started ...

-----Original Message-----
From: users-bounces at lists.opensips.org [mailto:users-bounces at lists.opensips.org] On Behalf Of Bogdan-Andrei Iancu
Sent: Thursday, January 22, 2009 9:15 AM
Hi Matti,

no, there is no other solution - using M4 is the cleverest solution ;)

Regards,
Bogdan

Matti Zemack wrote:
>
> Hi again,
>
> First of all, Thanks for all help I received previously today. 
> Fantastic and very quick response.
>
> So here is my second newbie-question: Is there any way to include 
> files at startup? It would be nice to split a 2000+ lines config file 
> into easier to handle parts.
>
> (After this morning tip from Iñaki, I suppose I could use m4 for this 
> errand... Any other clever suggestions?)
>
> Best Regards,
>
> Matti Zemack
>
> Stockholm
>
> Sweden




More information about the Users mailing list