Browse code

- cfg_core.c and cfg_core.h are added to the repository as a placeholder of the core configuration.

- debug level is switched to the new config variable type. From now,
it is changeble runtime.

Miklos Tirpak authored on 05/12/2007 16:21:36
Showing 5 changed files
... ...
@@ -117,6 +117,7 @@
117 117
 #include "tcp_options.h"
118 118
 
119 119
 #include "config.h"
120
+#include "cfg_core.h"
120 121
 #ifdef CORE_TLS
121 122
 #include "tls/tls_config.h"
122 123
 #endif
... ...
@@ -587,7 +588,7 @@ avpflag_spec:
587 587
 	}
588 588
 	;
589 589
 assign_stm:
590
-	DEBUG_V EQUAL NUMBER { debug=$3; }
590
+	DEBUG_V EQUAL NUMBER { default_core_cfg.debug=$3; }
591 591
 	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
592 592
 	| FORK  EQUAL NUMBER { dont_fork= ! $3; }
593 593
 	| FORK  EQUAL error  { yyerror("boolean value expected"); }
594 594
new file mode 100644
... ...
@@ -0,0 +1,45 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (C) 2007 iptelorg GmbH
4
+ *
5
+ * This file is part of ser, a free SIP server.
6
+ *
7
+ * ser is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version
11
+ *
12
+ * For a license to use the ser software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * ser is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program; if not, write to the Free Software
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ *
26
+ * History
27
+ * -------
28
+ *  2007-12-03	Initial version (Miklos)
29
+ */
30
+
31
+#include "dprint.h"
32
+#include "cfg/cfg.h"
33
+#include "cfg_core.h"
34
+
35
+struct cfg_group_core default_core_cfg = {
36
+	L_DEFAULT /*  print only msg. < L_WARN */
37
+};
38
+
39
+void	*core_cfg = &default_core_cfg;
40
+
41
+cfg_def_t core_cfg_def[] = {
42
+	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
43
+	{0, 0, 0, 0, 0, 0}
44
+};
0 45
new file mode 100644
... ...
@@ -0,0 +1,54 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (C) 2007 iptelorg GmbH
4
+ *
5
+ * This file is part of ser, a free SIP server.
6
+ *
7
+ * ser is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version
11
+ *
12
+ * For a license to use the ser software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * ser is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program; if not, write to the Free Software
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ *
26
+ * HOWTO:
27
+ *	If you need a new configuration variable within the core, put it into
28
+ *	struct cfg_goup_core, and define it in cfg_core.c:core_cfg_def array.
29
+ *	The default value of the variable must be inserted into
30
+ *	cfg_core.c:default_core_cfg
31
+ *	Include this header file in your source code, and retrieve the
32
+ *	value with cfg_get(core, core_cfg, variable_name).
33
+ *
34
+ * History
35
+ * -------
36
+ *  2007-12-03	Initial version (Miklos)
37
+ */
38
+
39
+#ifndef _CFG_CORE_H
40
+#define _CFG_CORE_H
41
+
42
+#include "cfg/cfg.h"
43
+
44
+extern void	*core_cfg;
45
+
46
+struct cfg_group_core {
47
+	int	debug;
48
+};
49
+
50
+extern struct cfg_group_core default_core_cfg;
51
+extern cfg_def_t core_cfg_def[];
52
+
53
+#endif /* _CFG_CORE_H */
... ...
@@ -31,6 +31,7 @@
31 31
 #define dprint_h
32 32
 
33 33
 #include <syslog.h>
34
+#include "cfg_core.h"
34 35
 
35 36
 
36 37
 #define L_ALERT -3
... ...
@@ -44,7 +45,6 @@
44 44
 
45 45
 /* vars:*/
46 46
 
47
-extern int debug;
48 47
 extern int log_stderr;
49 48
 extern int log_facility;
50 49
 extern volatile int dprint_crit; /* protection against "simultaneous"
... ...
@@ -98,7 +98,7 @@ int str2facility(char *s);
98 98
 	#ifdef __SUNPRO_C
99 99
 		#define DPrint( ...) \
100 100
 			do{ \
101
-				if ((debug>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
101
+				if ((cfg_get(core, core_cfg, debug)>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
102 102
 					DPRINT_CRIT_ENTER; \
103 103
 					if (log_stderr){ \
104 104
 						dprint (__VA_ARGS__); \
... ...
@@ -111,7 +111,7 @@ int str2facility(char *s);
111 111
 	#else
112 112
 			#define DPrint(fmt,args...) \
113 113
 			do{ \
114
-				if ((debug>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
114
+				if ((cfg_get(core, core_cfg, debug)>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
115 115
 					DPRINT_CRIT_ENTER; \
116 116
 					if (log_stderr){ \
117 117
 						dprint (fmt, ## args); \
... ...
@@ -139,7 +139,7 @@ int str2facility(char *s);
139 139
 	#ifdef __SUNPRO_C
140 140
 		#define LOG(lev, ...) \
141 141
 			do { \
142
-				if ((debug>=(lev)) && DPRINT_NON_CRIT){ \
142
+				if ((cfg_get(core, core_cfg, debug)>=(lev)) && DPRINT_NON_CRIT){ \
143 143
 					DPRINT_CRIT_ENTER; \
144 144
 					if (log_stderr) dprint (__VA_ARGS__); \
145 145
 					else { \
... ...
@@ -173,7 +173,7 @@ int str2facility(char *s);
173 173
 	#else
174 174
 		#define LOG(lev, fmt, args...) \
175 175
 			do { \
176
-				if ((debug>=(lev)) && DPRINT_NON_CRIT){ \
176
+				if ((cfg_get(core, core_cfg, debug)>=(lev)) && DPRINT_NON_CRIT){ \
177 177
 					DPRINT_CRIT_ENTER; \
178 178
 					if (log_stderr) dprint (fmt, ## args); \
179 179
 					else { \
... ...
@@ -159,7 +159,9 @@
159 159
 #include "rand/fastrand.h" /* seed */
160 160
 
161 161
 #include "stats.h"
162
+#include "cfg/cfg.h"
162 163
 #include "cfg/cfg_struct.h"
164
+#include "cfg_core.h"
163 165
 
164 166
 #ifdef DEBUG_DMALLOC
165 167
 #include <dmalloc.h>
... ...
@@ -293,7 +295,6 @@ gen_lock_t* process_lock;		/* lock on the process table */
293 293
 int process_no = 0;				/* index of process in the pt */
294 294
 
295 295
 int sig_flag = 0;              /* last signal received */
296
-int debug = L_DEFAULT; /* print only msg. < L_WARN */
297 296
 int dont_fork = 0;
298 297
 int dont_daemonize = 0;
299 298
 int log_stderr = 0;
... ...
@@ -1292,7 +1293,7 @@ int main(int argc, char** argv)
1292 1292
 					break;
1293 1293
 			case 'd':
1294 1294
 					debug_flag = 1;
1295
-					debug++;
1295
+					default_core_cfg.debug++;
1296 1296
 					break;
1297 1297
 			case 'V':
1298 1298
 					printf("version: %s\n", version);
... ...
@@ -1387,7 +1388,7 @@ try_again:
1387 1387
 	init_named_flags();
1388 1388
 
1389 1389
 	yyin=cfg_stream;
1390
-	debug_save = debug;
1390
+	debug_save = default_core_cfg.debug;
1391 1391
 	if ((yyparse()!=0)||(cfg_errors)){
1392 1392
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
1393 1393
 		goto error;
... ...
@@ -1395,7 +1396,7 @@ try_again:
1395 1395
 	if (cfg_warnings){
1396 1396
 		fprintf(stderr, "%d config warnings\n", cfg_warnings);
1397 1397
 	}
1398
-	if (debug_flag) debug = debug_save;
1398
+	if (debug_flag) default_core_cfg.debug = debug_save;
1399 1399
 	print_rls();
1400 1400
 
1401 1401
 	/* options with higher priority than cfg file */
... ...
@@ -1670,6 +1671,13 @@ try_again:
1670 1670
 		LOG(L_CRIT, "could not initialize configuration framework\n");
1671 1671
 		goto error;
1672 1672
 	}
1673
+	/* declare the core cfg before the module configs */
1674
+	if (cfg_declare("core", core_cfg_def, &default_core_cfg, cfg_size(core),
1675
+			&core_cfg)
1676
+	) {
1677
+		LOG(L_CRIT, "could not declare the core configuration\n");
1678
+		goto error;
1679
+	}
1673 1680
 	
1674 1681
 	if (init_modules() != 0) {
1675 1682
 		fprintf(stderr, "ERROR: error while initializing modules\n");