kamailio.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
List overview
Download
sr-dev
September 2012
----- 2024 -----
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
sr-dev@lists.kamailio.org
32 participants
173 discussions
Start a n
N
ew thread
git:3.3: core: Use Colin Plumb's MD5 implementation
by Daniel-Constantin Mierla
Module: sip-router Branch: 3.3 Commit: fbd4acae2d732908a9624c727b8b0306e1c166cd URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fbd4aca…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Thu Aug 2 10:13:00 2012 +0200 core: Use Colin Plumb's MD5 implementation Origin:
http://anonscm.debian.org/gitweb/?p=dpkg/dpkg.git;a=summary
Author: Tzafrir Cohen <tzafrir(a)debian.org> Borrowed the md5 code from dpkg instead of the existing md5.[ch] This makes the code compatible with Debian packing rules and restrictions regarding license for distribution (cherry picked from commit e6d912ad036aa92604ba3f2bf65cc4c4ba3e4d2f) --- md5.c | 535 +++++++++++++++++++++++++++-------------------------------------- md5.h | 120 +++------------ 2 files changed, 248 insertions(+), 407 deletions(-) Diff:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=fbd…
12 years, 2 months
1
0
0
0
git:3.3: Add Record-Route for in-dialog NOTIFY as per RFC 6665.
by Daniel-Constantin Mierla
Module: sip-router Branch: 3.3 Commit: cd1e3909f03f837a583b9ea30ffd6089b8ba8db2 URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cd1e390…
Author: Iñaki Baz Castillo <ibc(a)aliax.net> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Thu Aug 16 16:13:50 2012 +0200 Add Record-Route for in-dialog NOTIFY as per RFC 6665. (cherry picked from commit d661028060369e702f5882b6492040bd71fb900a) --- etc/kamailio.cfg | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/etc/kamailio.cfg b/etc/kamailio.cfg index e6f20dc..1dd4b21 100644 --- a/etc/kamailio.cfg +++ b/etc/kamailio.cfg @@ -574,10 +574,14 @@ route[WITHINDLG] { setflag(FLT_ACC); # do accounting ... setflag(FLT_ACCFAILED); # ... even if the transaction fails } - if ( is_method("ACK") ) { + else if ( is_method("ACK") ) { # ACK is forwarded statelessy route(NATMANAGE); } + else if ( is_method("NOTIFY") ) { + # Add Record-Route for in-dialog NOTIFY as per RFC 6665. + record_route(); + } route(RELAY); } else { if (is_method("SUBSCRIBE") && uri == myself) {
12 years, 2 months
1
0
0
0
git:3.3: Process CANCEL before in-dialog requests. This prevents issues with some devices sending buggy CANCEL with To-tag when cancelling an initial INVITE .
by Daniel-Constantin Mierla
Module: sip-router Branch: 3.3 Commit: 20dacf5225e63fc8ff573272f41572f452272c7d URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=20dacf5…
Author: Iñaki Baz Castillo <ibc(a)aliax.net> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Thu Aug 16 16:17:51 2012 +0200 Process CANCEL before in-dialog requests. This prevents issues with some devices sending buggy CANCEL with To-tag when cancelling an initial INVITE. (cherry picked from commit 8a7a06f4d9c78f6da0558806d988c817fd6d0018) --- etc/kamailio.cfg | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/etc/kamailio.cfg b/etc/kamailio.cfg index 1dd4b21..619f9ad 100644 --- a/etc/kamailio.cfg +++ b/etc/kamailio.cfg @@ -452,11 +452,6 @@ request_route { # NAT detection route(NATDETECT); - # handle requests within SIP dialogs - route(WITHINDLG); - - ### only initial requests (no To tag) - # CANCEL processing if (is_method("CANCEL")) { @@ -465,6 +460,11 @@ request_route { exit; } + # handle requests within SIP dialogs + route(WITHINDLG); + + ### only initial requests (no To tag) + t_check_trans(); # authentication
12 years, 2 months
1
0
0
0
git:3.3: kamailio.cfg: use add_contact_alias()/handle_uri_alias() for NATed calls
by Daniel-Constantin Mierla
Module: sip-router Branch: 3.3 Commit: 80e5d5689963ab01a9ab3b3ba7d39f08df59b213 URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=80e5d56…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Fri Jun 29 16:06:42 2012 +0200 kamailio.cfg: use add_contact_alias()/handle_uri_alias() for NATed calls (cherry picked from commit 9d720b83c9dd27e927627132ec052b15efeba518) --- etc/kamailio.cfg | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/etc/kamailio.cfg b/etc/kamailio.cfg index f8b375c..e6f20dc 100644 --- a/etc/kamailio.cfg +++ b/etc/kamailio.cfg @@ -569,6 +569,7 @@ route[WITHINDLG] { # sequential request withing a dialog should # take the path determined by record-routing if (loose_route()) { + route(DLGURI); if (is_method("BYE")) { setflag(FLT_ACC); # do accounting ... setflag(FLT_ACCFAILED); # ... even if the transaction fails @@ -736,7 +737,7 @@ route[NATDETECT] { if (is_method("REGISTER")) { fix_nated_register(); } else { - fix_nated_contact(); + add_contact_alias(); } setflag(FLT_NATS); } @@ -766,13 +767,23 @@ route[NATMANAGE] { } if (is_reply()) { if(isbflagset(FLB_NATB)) { - fix_nated_contact(); + add_contact_alias(); } } #!endif return; } +# URI update for dialog requests +route[DLGURI] { +#!ifdef WITH_NAT + if(!isdsturiset()) { + handle_ruri_alias(); + } +#!endif + return; +} + # Routing to foreign domains route[SIPOUT] { if (!uri==myself)
12 years, 2 months
1
0
0
0
git:master: prefix_route: new parameter to control the exit from config
by Daniel-Constantin Mierla
Module: sip-router Branch: master Commit: dfc98801110554f92aeaa80594e01cad16c9dcd1 URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dfc9880…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Sun Sep 2 13:29:18 2012 +0200 prefix_route: new parameter to control the exit from config - 'exit' controls if prefix_route() triggers cfg exit or returns true upon matching a prefix. Default is 1 (on) for backward compatibility - prefix_route() takes an optional parameter that can be used to match the prefix instead of r-uri username --- modules/prefix_route/README | 37 +++++++++++++++++++++++++------- modules/prefix_route/doc/functions.xml | 13 +++++++++- modules/prefix_route/doc/params.xml | 20 +++++++++++++++++ modules/prefix_route/prefix_route.c | 29 ++++++++++++++++++------- 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/modules/prefix_route/README b/modules/prefix_route/README index 92a9024..0aa4780 100644 --- a/modules/prefix_route/README +++ b/modules/prefix_route/README @@ -4,9 +4,9 @@ Alfred E. Heggestad Telio Telecom - Copyright © 2007 Alfred E. Heggestad + Copyright � 2007 Alfred E. Heggestad - Copyright © 2008 Telio Telecom AS + Copyright � 2008 Telio Telecom AS __________________________________________________________________ 1.1. Overview @@ -14,10 +14,11 @@ Alfred E. Heggestad 1.2.1. db_url (string) 1.2.2. db_table (string) + 1.2.3. exit (int) 1.3. Functions - 1.3.1. prefix_route() + 1.3.1. prefix_route([user]) 1.4. RPC Commands @@ -63,20 +64,40 @@ modparam("prefix_route", "db_url", "mysql://ser:pass@db_host/ser") modparam("prefix_route", "db_table", "new_prefix_route") ... +1.2.3. exit (int) + + If set, exit the execution of the configuration file when a route block + is executed upon matching a prefix. Otherwise return 1 (true). + + Default value is 1 (on). + + Example 3. Setting exit parameter +... +modparam("prefix_route", "exit", 0) +... + 1.3. Functions -1.3.1. prefix_route() +1.3.1. prefix_route([user]) This function tries to find a route from the user part of the request - URI. If a route is found, it will be used for further processing. - Otherwise the function will return false. + URI (if no parameter is provided), or from the value of the parameter. + The parameter can contain config variables. - Example 3. prefix_route() usage + If a route is found, it will be used for further processing. Otherwise + the function will return false. + + Example 4. prefix_route() usage ... if (!prefix_route()) { xlog("L_ERR", "prefix_route(): no matching routes\n"); } ... + if (!prefix_route("$fU")) { + xlog("L_ERR", "prefix_route(): no matching routes\n"); + } + +... 1.4. RPC Commands @@ -96,7 +117,7 @@ modparam("prefix_route", "db_table", "new_prefix_route") * route - varchar(64) - Route name * comment - varchar(64) - Free-form comment - Example 4. Sample data + Example 5. Sample data ... +--------+-------+---------------+ | prefix | route | comment | diff --git a/modules/prefix_route/doc/functions.xml b/modules/prefix_route/doc/functions.xml index fd71954..34f86a7 100644 --- a/modules/prefix_route/doc/functions.xml +++ b/modules/prefix_route/doc/functions.xml @@ -6,9 +6,13 @@ <title>Functions</title> <section id="prefixroute.prefix_route"> - <title><function>prefix_route()</function></title> + <title><function>prefix_route([user])</function></title> + <para> + This function tries to find a route from the user part of the request URI + (if no parameter is provided), or from the value of the parameter. The + parameter can contain config variables. + </para> <para> - This function tries to find a route from the user part of the request URI. If a route is found, it will be used for further processing. Otherwise the function will return false. </para> @@ -20,6 +24,11 @@ xlog("L_ERR", "prefix_route(): no matching routes\n"); } ... + if (!prefix_route("$fU")) { + xlog("L_ERR", "prefix_route(): no matching routes\n"); + } + +... </programlisting> </example> </section> diff --git a/modules/prefix_route/doc/params.xml b/modules/prefix_route/doc/params.xml index 80bb4e0..b584ac3 100644 --- a/modules/prefix_route/doc/params.xml +++ b/modules/prefix_route/doc/params.xml @@ -41,4 +41,24 @@ modparam("prefix_route", "db_table", "new_prefix_route") </example> </section> + <section id="prefixroute.exit"> + <title><varname>exit</varname> (int)</title> + <para> + If set, exit the execution of the configuration file + when a route block is executed upon matching a prefix. + Otherwise return 1 (true). + </para> + <para> + Default value is 1 (on). + </para> + <example> + <title>Setting exit parameter</title> + <programlisting> +... +modparam("prefix_route", "exit", 0) +... + </programlisting> + </example> + </section> + </section> diff --git a/modules/prefix_route/prefix_route.c b/modules/prefix_route/prefix_route.c index be52f9b..7ae8383 100644 --- a/modules/prefix_route/prefix_route.c +++ b/modules/prefix_route/prefix_route.c @@ -32,6 +32,7 @@ #include "../../lib/srdb2/db.h" #include "../../rpc.h" #include "../../sr_module.h" +#include "../../mod_fix.h" #include "../../mem/mem.h" #include "../../data_lump_rpl.h" #include "../../parser/parse_uri.h" @@ -49,7 +50,7 @@ MODULE_VERSION /* Modules parameters */ static char *db_url = DEFAULT_DB_URL; static char *db_table = "prefix_route"; - +static int prefix_route_exit = 1; static int add_route(struct tree_item *root, const char *prefix, const char *route) @@ -265,11 +266,19 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2) (void)p2; /* Get request URI */ - err = get_username(msg, &user); - if (0 != err) { - LOG(L_ERR, "prefix_route: could not get username in" - " Request URI (%d)\n", err); - return err; + if(p1==NULL) { + err = get_username(msg, &user); + if (0 != err) { + LOG(L_ERR, "prefix_route: could not get username in" + " Request URI (%d)\n", err); + return err; + } + } else { + if(fixup_get_svalue(msg, (gparam_t*)p1, &user)<0) + { + LOG(L_ERR, "could not get username in parameter\n"); + return -1; + } } route = tree_route_get(&user); @@ -286,7 +295,7 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2) } /* Success */ - return 0; + return (prefix_route_exit)?0:1; } @@ -294,7 +303,10 @@ static int prefix_route(struct sip_msg *msg, char *p1, char *p2) * Exported functions */ static cmd_export_t cmds[] = { - {"prefix_route", prefix_route, 0, 0, REQUEST_ROUTE}, + {"prefix_route", prefix_route, 0, 0, + REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE}, + {"prefix_route", prefix_route, 1, fixup_spve_null, + ANY_ROUTE}, {0, 0, 0, 0, 0 } }; @@ -304,6 +316,7 @@ static cmd_export_t cmds[] = { static param_export_t params[] = { {"db_url", STR_PARAM, &db_url }, {"db_table", STR_PARAM, &db_table}, + {"exit", INT_PARAM, &prefix_route_exit}, {0, 0, 0 } };
12 years, 2 months
1
0
0
0
git:master: tm: new config parameter - remap_503_500
by Daniel-Constantin Mierla
Module: sip-router Branch: master Commit: ca57c8631511943e835e8b030dad638f92aff884 URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ca57c86…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Sun Sep 2 11:59:38 2012 +0200 tm: new config parameter - remap_503_500 - option to disable remapping of 503 response code to 500 --- modules/tm/README | 92 ++++++++++++++++++++++++++------------------ modules/tm/doc/params.xml | 22 +++++++++++ modules/tm/t_reply.c | 5 ++- modules/tm/tm.c | 3 + 4 files changed, 83 insertions(+), 39 deletions(-) Diff:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=ca5…
12 years, 2 months
1
0
0
0
git:master: srdb1: table_name set to unique constraint in version table
by Daniel-Constantin Mierla
Module: sip-router Branch: master Commit: 886a0659449bc03bd7c5e852fe6ba29a17ad923d URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=886a065…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Sun Sep 2 13:08:53 2012 +0200 srdb1: table_name set to unique constraint in version table --- lib/srdb1/schema/version.xml | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/srdb1/schema/version.xml b/lib/srdb1/schema/version.xml index ae3c615..298f32a 100644 --- a/lib/srdb1/schema/version.xml +++ b/lib/srdb1/schema/version.xml @@ -10,15 +10,20 @@ <name>version</name> <type db="mysql">&MYSQL_TABLE_TYPE;</type> - <column id="tn"> + <column id="table_name"> <name>table_name</name> <type>string</type> <size>32</size> <natural/> </column> - <column id="tv"> + <column id="table_version"> <name>table_version</name> <type>unsigned int</type> <default>0</default> </column> + <index> + <name>table_name_idx</name> + <colref linkend="table_name"/> + <unique/> + </index> </table>
12 years, 2 months
1
0
0
0
git:master: kamctl: regenerated db creation scripts
by Daniel-Constantin Mierla
Module: sip-router Branch: master Commit: e09b5bc8f7d17d8d9d9754152d78b0c835e94a9f URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e09b5bc…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com> Committer: Daniel-Constantin Mierla <miconda(a)gmail.com> Date: Sun Sep 2 13:36:55 2012 +0200 kamctl: regenerated db creation scripts --- utils/kamctl/db_sqlite/standard-create.sql | 3 ++- utils/kamctl/mysql/standard-create.sql | 3 ++- utils/kamctl/oracle/standard-create.sql | 3 ++- utils/kamctl/postgres/standard-create.sql | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/kamctl/db_sqlite/standard-create.sql b/utils/kamctl/db_sqlite/standard-create.sql index 0add99d..ae5ce2a 100644 --- a/utils/kamctl/db_sqlite/standard-create.sql +++ b/utils/kamctl/db_sqlite/standard-create.sql @@ -1,5 +1,6 @@ CREATE TABLE version ( table_name VARCHAR(32) NOT NULL, - table_version INTEGER DEFAULT 0 NOT NULL + table_version INTEGER DEFAULT 0 NOT NULL, + CONSTRAINT version_table_name_idx UNIQUE (table_name) ); diff --git a/utils/kamctl/mysql/standard-create.sql b/utils/kamctl/mysql/standard-create.sql index 42dbaf6..d76d450 100644 --- a/utils/kamctl/mysql/standard-create.sql +++ b/utils/kamctl/mysql/standard-create.sql @@ -1,5 +1,6 @@ CREATE TABLE version ( table_name VARCHAR(32) NOT NULL, - table_version INT UNSIGNED DEFAULT 0 NOT NULL + table_version INT UNSIGNED DEFAULT 0 NOT NULL, + CONSTRAINT table_name_idx UNIQUE (table_name) ) ENGINE=MyISAM; diff --git a/utils/kamctl/oracle/standard-create.sql b/utils/kamctl/oracle/standard-create.sql index 23f5525..6f29e49 100644 --- a/utils/kamctl/oracle/standard-create.sql +++ b/utils/kamctl/oracle/standard-create.sql @@ -1,6 +1,7 @@ CREATE TABLE version ( table_name VARCHAR2(32), - table_version NUMBER(10) DEFAULT 0 NOT NULL + table_version NUMBER(10) DEFAULT 0 NOT NULL, + CONSTRAINT version_table_name_idx UNIQUE (table_name) ); BEGIN map2users('version'); END; diff --git a/utils/kamctl/postgres/standard-create.sql b/utils/kamctl/postgres/standard-create.sql index 0add99d..ae5ce2a 100644 --- a/utils/kamctl/postgres/standard-create.sql +++ b/utils/kamctl/postgres/standard-create.sql @@ -1,5 +1,6 @@ CREATE TABLE version ( table_name VARCHAR(32) NOT NULL, - table_version INTEGER DEFAULT 0 NOT NULL + table_version INTEGER DEFAULT 0 NOT NULL, + CONSTRAINT version_table_name_idx UNIQUE (table_name) );
12 years, 2 months
1
0
0
0
git:master: core: -e - new cli parameter to enable colorful log messages
by Elena-Ramona Modroiu
Module: sip-router Branch: master Commit: 6bda9c0b7aac195902d2c42123bdde007a9a687f URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6bda9c0…
Author: Elena-Ramona Modroiu <ramona(a)asipto.com> Committer: Elena-Ramona Modroiu <ramona(a)asipto.com> Date: Sat Sep 1 16:16:21 2012 +0200 core: -e - new cli parameter to enable colorful log messages - used only when log messages are printed to stderr - each log level is printed in different color, using term colors (like $C(xy) variable) --- dprint.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dprint.h | 15 +++++ main.c | 19 +++++- 3 files changed, 235 insertions(+), 2 deletions(-) diff --git a/dprint.c b/dprint.c index 324d511..90dd110 100644 --- a/dprint.c +++ b/dprint.c @@ -140,3 +140,206 @@ void reset_local_debug_level(void) { _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; } + +typedef struct log_level_color { + char f; + char b; +} log_level_color_t; + +log_level_color_t _log_level_colors[L_MAX - L_MIN + 1]; + +void dprint_init_colors(void) +{ + int i; + + i = 0; + + memset(_log_level_colors, 0, + (L_MAX - L_MIN + 1)*sizeof(log_level_color_t)); + + /* L_ALERT */ + _log_level_colors[i].f = 'R'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_BUG */ + _log_level_colors[i].f = 'P'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_CRIT2 */ + _log_level_colors[i].f = 'y'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_CRIT */ + _log_level_colors[i].f = 'b'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_ERR */ + _log_level_colors[i].f = 'r'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_WARN */ + _log_level_colors[i].f = 'p'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_NOTICE */ + _log_level_colors[i].f = 'g'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_INFO */ + _log_level_colors[i].f = 'c'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; + + /* L_DBG */ + _log_level_colors[i].f = 'x'; /* default */ + _log_level_colors[i].b = 'x'; /* default */ + i++; +} + +#define TERM_COLOR_SIZE 16 + +#define dprint_termc_add(p, end, s) \ + do{ \ + if ((p)+(sizeof(s)-1)<=(end)){ \ + memcpy((p), s, sizeof(s)-1); \ + (p)+=sizeof(s)-1; \ + }else{ \ + /* overflow */ \ + LM_ERR("dprint_termc_add overflow\n"); \ + goto error; \ + } \ + } while(0) + + +void dprint_term_color(char f, char b, str *obuf) +{ + static char term_color[TERM_COLOR_SIZE]; + char* p; + char* end; + + p = term_color; + end = p + TERM_COLOR_SIZE; + + /* excape sequence */ + dprint_termc_add(p, end, "\033["); + + if(f!='_') + { + if (islower((int)f)) + { + /* normal font */ + dprint_termc_add(p, end, "0;"); + } else { + /* bold font */ + dprint_termc_add(p, end, "1;"); + f += 32; + } + } + + /* foreground */ + switch(f) + { + case 'x': + dprint_termc_add(p, end, "39;"); + break; + case 's': + dprint_termc_add(p, end, "30;"); + break; + case 'r': + dprint_termc_add(p, end, "31;"); + break; + case 'g': + dprint_termc_add(p, end, "32;"); + break; + case 'y': + dprint_termc_add(p, end, "33;"); + break; + case 'b': + dprint_termc_add(p, end, "34;"); + break; + case 'p': + dprint_termc_add(p, end, "35;"); + break; + case 'c': + dprint_termc_add(p, end, "36;"); + break; + case 'w': + dprint_termc_add(p, end, "37;"); + break; + default: + dprint_termc_add(p, end, "39;"); + } + + /* background */ + switch(b) + { + case 'x': + dprint_termc_add(p, end, "49"); + break; + case 's': + dprint_termc_add(p, end, "40"); + break; + case 'r': + dprint_termc_add(p, end, "41"); + break; + case 'g': + dprint_termc_add(p, end, "42"); + break; + case 'y': + dprint_termc_add(p, end, "43"); + break; + case 'b': + dprint_termc_add(p, end, "44"); + break; + case 'p': + dprint_termc_add(p, end, "45"); + break; + case 'c': + dprint_termc_add(p, end, "46"); + break; + case 'w': + dprint_termc_add(p, end, "47"); + break; + default: + dprint_termc_add(p, end, "49"); + } + + /* end */ + dprint_termc_add(p, end, "m"); + + obuf->s = term_color; + obuf->len = p - term_color; + return; + +error: + obuf->s = term_color; + term_color[0] = '\0'; + obuf->len = 0; +} + +void dprint_color(int level) +{ + str obuf; + + if(level<L_MIN || level>L_MAX) + return; + dprint_term_color(_log_level_colors[level - L_MIN].f, + _log_level_colors[level - L_MIN].b, + &obuf); + fprintf(stderr, "%.*s", obuf.len, obuf.s); +} + +void dprint_color_reset(void) +{ + str obuf; + + dprint_term_color('x', 'x', &obuf); + fprintf(stderr, "%.*s", obuf.len, obuf.s); +} diff --git a/dprint.h b/dprint.h index 6898c9f..04179de 100644 --- a/dprint.h +++ b/dprint.h @@ -81,6 +81,7 @@ /* * Log levels */ +#define L_MIN -5 #define L_ALERT -5 #define L_BUG -4 #define L_CRIT2 -3 /* like L_CRIT, but adds prefix */ @@ -90,6 +91,7 @@ #define L_NOTICE 1 #define L_INFO 2 #define L_DBG 3 +#define L_MAX 3 /** @brief This is the facility value used to indicate that the caller of the macro * did not override the facility. Value 0 (the defaul) is LOG_KERN on Linux @@ -109,6 +111,8 @@ extern int my_pid(void); /** @brief non-zero if logging to stderr instead to the syslog */ extern int log_stderr; +extern int log_color; + /** @brief maps log levels to their string name and corresponding syslog level */ struct log_level_info { @@ -133,6 +137,9 @@ extern volatile int dprint_crit; int str2facility(char *s); int log_facility_fixup(void *handle, str *gname, str *name, void **val); +void dprint_color(int level); +void dprint_color_reset(void); +void dprint_init_colors(void); /** @brief * General logging macros @@ -175,10 +182,12 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val); DPRINT_CRIT_ENTER; \ if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \ if (unlikely(log_stderr)) { \ + if (unlikely(log_color)) dprint_color(level); \ fprintf(stderr, "%2d(%d) %s: %s" fmt, \ process_no, my_pid(), \ LOG_LEVEL2NAME(level), (prefix), \ __VA_ARGS__); \ + if (unlikely(log_color)) dprint_color_reset(); \ } else { \ syslog(LOG2SYSLOG_LEVEL(level) | \ (((facility) != DEFAULT_FACILITY) ? \ @@ -189,9 +198,11 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val); } \ } else { \ if (log_stderr) { \ + if (unlikely(log_color)) dprint_color(level); \ fprintf(stderr, "%2d(%d) %s" fmt, \ process_no, my_pid(), \ (prefix), __VA_ARGS__); \ + if (unlikely(log_color)) dprint_color_reset(); \ } else { \ if ((level)<L_ALERT) \ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \ @@ -237,10 +248,12 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val); DPRINT_CRIT_ENTER; \ if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \ if (unlikely(log_stderr)) { \ + if (unlikely(log_color)) dprint_color(level); \ fprintf(stderr, "%2d(%d) %s: %s" fmt, \ process_no, my_pid(), \ LOG_LEVEL2NAME(level), \ (prefix) , ## args);\ + if (unlikely(log_color)) dprint_color_reset(); \ } else { \ syslog(LOG2SYSLOG_LEVEL(level) |\ (((facility) != DEFAULT_FACILITY) ? \ @@ -251,9 +264,11 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val); } \ } else { \ if (log_stderr) { \ + if (unlikely(log_color)) dprint_color(level); \ fprintf(stderr, "%2d(%d) %s" fmt, \ process_no, my_pid(), \ (prefix) , ## args); \ + if (unlikely(log_color)) dprint_color_reset(); \ } else { \ if ((level)<L_ALERT) \ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \ diff --git a/main.c b/main.c index ca272e1..cf3d665 100644 --- a/main.c +++ b/main.c @@ -229,7 +229,8 @@ Options:\n\ -d Debugging mode (multiple -d increase the level)\n\ -D no 1..do not fork (almost) anyway, 2..do not daemonize creator\n\ 3..daemonize (default)\n\ - -E Log to stderr\n" + -E Log to stderr\n\ + -e Log messages printed in terminal colors (requires -E)\n" #ifdef USE_TCP " -T Disable tcp\n\ -N Number of tcp child processes (default: equal to `-n')\n\ @@ -373,6 +374,7 @@ int sig_flag = 0; /* last signal received */ int dont_fork = 0; int dont_daemonize = 0; int log_stderr = 0; +int log_color = 0; /* set custom app name for syslog printing */ char *log_name = 0; pid_t creator_pid = (pid_t) -1; @@ -1854,8 +1856,11 @@ int main(int argc, char** argv) dont_fork_cnt=0; daemon_status_init(); + + dprint_init_colors(); + /* command line options */ - options= ":f:cm:M:dVIhEb:l:L:n:vrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:" + options= ":f:cm:M:dVIhEeb:l:L:n:vrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:" #ifdef STATS "s:" #endif @@ -1878,6 +1883,9 @@ int main(int argc, char** argv) case 'E': log_stderr=1; break; + case 'e': + log_color=1; + break; case 'M': pkg_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024; if (tmp &&(*tmp)){ @@ -1972,6 +1980,9 @@ int main(int argc, char** argv) case 'E': /* ignore it, was parsed immediately after startup */ break; + case 'e': + /* ignore it, was parsed immediately after startup */ + break; case 'O': scr_opt_lev=strtol(optarg, &tmp, 10); if (tmp &&(*tmp)){ @@ -2128,6 +2139,10 @@ try_again: log_stderr=1; /* use in both getopt switches, takes priority over config */ break; + case 'e': + log_color=1; /* use in both getopt switches, + takes priority over config */ + break; case 'b': maxbuffer=strtol(optarg, &tmp, 10); if (tmp &&(*tmp)){
12 years, 2 months
1
0
0
0
git:master: core: log_color - new global parameter to enable colorful log messages
by Elena-Ramona Modroiu
Module: sip-router Branch: master Commit: fe00a3346a2276b25ae26160ce76bf658b5b826e URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fe00a33…
Author: Elena-Ramona Modroiu <ramona(a)asipto.com> Committer: Elena-Ramona Modroiu <ramona(a)asipto.com> Date: Sat Sep 1 16:24:02 2012 +0200 core: log_color - new global parameter to enable colorful log messages - enabled only when log_stderr=1 - equivalent of -e command parameter - it can be: 0 - disabled (no colors, default); 1 - enabled --- cfg.lex | 2 ++ cfg.y | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/cfg.lex b/cfg.lex index f986354..b0f4733 100644 --- a/cfg.lex +++ b/cfg.lex @@ -342,6 +342,7 @@ FORK_DELAY fork_delay LOGSTDERROR log_stderror LOGFACILITY log_facility LOGNAME log_name +LOGCOLOR log_color LISTEN listen ADVERTISE advertise|ADVERTISE ALIAS alias @@ -717,6 +718,7 @@ IMPORTFILE "import_file" <INITIAL>{LOGSTDERROR} { yylval.strval=yytext; return LOGSTDERROR; } <INITIAL>{LOGFACILITY} { yylval.strval=yytext; return LOGFACILITY; } <INITIAL>{LOGNAME} { yylval.strval=yytext; return LOGNAME; } +<INITIAL>{LOGCOLOR} { yylval.strval=yytext; return LOGCOLOR; } <INITIAL>{LISTEN} { count(); yylval.strval=yytext; return LISTEN; } <INITIAL>{ADVERTISE} { count(); yylval.strval=yytext; return ADVERTISE; } <INITIAL>{ALIAS} { count(); yylval.strval=yytext; return ALIAS; } diff --git a/cfg.y b/cfg.y index 0ae0e40..37859aa 100644 --- a/cfg.y +++ b/cfg.y @@ -401,6 +401,7 @@ extern char *finame; %token LOGSTDERROR %token LOGFACILITY %token LOGNAME +%token LOGCOLOR %token LISTEN %token ADVERTISE %token ALIAS @@ -863,6 +864,8 @@ assign_stm: | LOGFACILITY EQUAL error { yyerror("ID expected"); } | LOGNAME EQUAL STRING { log_name=$3; } | LOGNAME EQUAL error { yyerror("string value expected"); } + | LOGCOLOR EQUAL NUMBER { log_color=$3; } + | LOGCOLOR EQUAL error { yyerror("boolean value expected"); } | DNS EQUAL NUMBER { received_dns|= ($3)?DO_DNS:0; } | DNS EQUAL error { yyerror("boolean value expected"); } | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
12 years, 2 months
1
0
0
0
← Newer
1
...
14
15
16
17
18
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Results per page:
10
25
50
100
200