Thursday, April 22, 2010

Kamailio 3.0.x - DYK-06 - comments with define

Comment big blocks with defines

See also: Kamailio 3.0.x - DYK - Table of Content

Kamailio 3.0.0 brought #!define directive support. This can be used as a neat and easy way to comment big blocks of config. Using multi-lines comment format in between /* */ is not convenient for nested cases.

Trying to enclose in multi-line comment a snippet like next (well, not that big in this example) is not straightforward:
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
Clearly is broken to do it like:
/*
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
*/
The option in 3.0.x is:
#!ifdef EXTRACOMMENT
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
#!endif
You can use anything you haven't defined instead of EXTRACOMMENT.

Enabling it is:
#!define EXTRACOMMENT
#!ifdef EXTRACOMMENT
/* log time and method */
xlog("SIP $rm at $Tf\n");
/* log source ip and port */
xlog("SIP from $si:$sp\n");
#!endif

No comments:

Post a Comment