Kaynağa Gözat

- 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 18 yıl önce
ebeveyn
işleme
7ac069af56
5 değiştirilmiş dosya ile 118 ekleme ve 10 silme
  1. 2 1
      cfg.y
  2. 45 0
      cfg_core.c
  3. 54 0
      cfg_core.h
  4. 5 5
      dprint.h
  5. 12 4
      main.c

+ 2 - 1
cfg.y

@@ -117,6 +117,7 @@
 #include "tcp_options.h"
 
 #include "config.h"
+#include "cfg_core.h"
 #ifdef CORE_TLS
 #include "tls/tls_config.h"
 #endif
@@ -587,7 +588,7 @@ avpflag_spec:
 	}
 	;
 assign_stm:
-	DEBUG_V EQUAL NUMBER { debug=$3; }
+	DEBUG_V EQUAL NUMBER { default_core_cfg.debug=$3; }
 	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
 	| FORK  EQUAL NUMBER { dont_fork= ! $3; }
 	| FORK  EQUAL error  { yyerror("boolean value expected"); }

+ 45 - 0
cfg_core.c

@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History
+ * -------
+ *  2007-12-03	Initial version (Miklos)
+ */
+
+#include "dprint.h"
+#include "cfg/cfg.h"
+#include "cfg_core.h"
+
+struct cfg_group_core default_core_cfg = {
+	L_DEFAULT /*  print only msg. < L_WARN */
+};
+
+void	*core_cfg = &default_core_cfg;
+
+cfg_def_t core_cfg_def[] = {
+	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
+	{0, 0, 0, 0, 0, 0}
+};

+ 54 - 0
cfg_core.h

@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2007 iptelorg GmbH
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * HOWTO:
+ *	If you need a new configuration variable within the core, put it into
+ *	struct cfg_goup_core, and define it in cfg_core.c:core_cfg_def array.
+ *	The default value of the variable must be inserted into
+ *	cfg_core.c:default_core_cfg
+ *	Include this header file in your source code, and retrieve the
+ *	value with cfg_get(core, core_cfg, variable_name).
+ *
+ * History
+ * -------
+ *  2007-12-03	Initial version (Miklos)
+ */
+
+#ifndef _CFG_CORE_H
+#define _CFG_CORE_H
+
+#include "cfg/cfg.h"
+
+extern void	*core_cfg;
+
+struct cfg_group_core {
+	int	debug;
+};
+
+extern struct cfg_group_core default_core_cfg;
+extern cfg_def_t core_cfg_def[];
+
+#endif /* _CFG_CORE_H */

+ 5 - 5
dprint.h

@@ -31,6 +31,7 @@
 #define dprint_h
 
 #include <syslog.h>
+#include "cfg_core.h"
 
 
 #define L_ALERT -3
@@ -44,7 +45,6 @@
 
 /* vars:*/
 
-extern int debug;
 extern int log_stderr;
 extern int log_facility;
 extern volatile int dprint_crit; /* protection against "simultaneous"
@@ -98,7 +98,7 @@ int str2facility(char *s);
 	#ifdef __SUNPRO_C
 		#define DPrint( ...) \
 			do{ \
-				if ((debug>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
+				if ((cfg_get(core, core_cfg, debug)>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
 					DPRINT_CRIT_ENTER; \
 					if (log_stderr){ \
 						dprint (__VA_ARGS__); \
@@ -111,7 +111,7 @@ int str2facility(char *s);
 	#else
 			#define DPrint(fmt,args...) \
 			do{ \
-				if ((debug>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
+				if ((cfg_get(core, core_cfg, debug)>=DPRINT_LEV) && DPRINT_NON_CRIT){ \
 					DPRINT_CRIT_ENTER; \
 					if (log_stderr){ \
 						dprint (fmt, ## args); \
@@ -139,7 +139,7 @@ int str2facility(char *s);
 	#ifdef __SUNPRO_C
 		#define LOG(lev, ...) \
 			do { \
-				if ((debug>=(lev)) && DPRINT_NON_CRIT){ \
+				if ((cfg_get(core, core_cfg, debug)>=(lev)) && DPRINT_NON_CRIT){ \
 					DPRINT_CRIT_ENTER; \
 					if (log_stderr) dprint (__VA_ARGS__); \
 					else { \
@@ -173,7 +173,7 @@ int str2facility(char *s);
 	#else
 		#define LOG(lev, fmt, args...) \
 			do { \
-				if ((debug>=(lev)) && DPRINT_NON_CRIT){ \
+				if ((cfg_get(core, core_cfg, debug)>=(lev)) && DPRINT_NON_CRIT){ \
 					DPRINT_CRIT_ENTER; \
 					if (log_stderr) dprint (fmt, ## args); \
 					else { \

+ 12 - 4
main.c

@@ -159,7 +159,9 @@
 #include "rand/fastrand.h" /* seed */
 
 #include "stats.h"
+#include "cfg/cfg.h"
 #include "cfg/cfg_struct.h"
+#include "cfg_core.h"
 
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
@@ -293,7 +295,6 @@ gen_lock_t* process_lock;		/* lock on the process table */
 int process_no = 0;				/* index of process in the pt */
 
 int sig_flag = 0;              /* last signal received */
-int debug = L_DEFAULT; /* print only msg. < L_WARN */
 int dont_fork = 0;
 int dont_daemonize = 0;
 int log_stderr = 0;
@@ -1292,7 +1293,7 @@ int main(int argc, char** argv)
 					break;
 			case 'd':
 					debug_flag = 1;
-					debug++;
+					default_core_cfg.debug++;
 					break;
 			case 'V':
 					printf("version: %s\n", version);
@@ -1387,7 +1388,7 @@ try_again:
 	init_named_flags();
 
 	yyin=cfg_stream;
-	debug_save = debug;
+	debug_save = default_core_cfg.debug;
 	if ((yyparse()!=0)||(cfg_errors)){
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
 		goto error;
@@ -1395,7 +1396,7 @@ try_again:
 	if (cfg_warnings){
 		fprintf(stderr, "%d config warnings\n", cfg_warnings);
 	}
-	if (debug_flag) debug = debug_save;
+	if (debug_flag) default_core_cfg.debug = debug_save;
 	print_rls();
 
 	/* options with higher priority than cfg file */
@@ -1670,6 +1671,13 @@ try_again:
 		LOG(L_CRIT, "could not initialize configuration framework\n");
 		goto error;
 	}
+	/* declare the core cfg before the module configs */
+	if (cfg_declare("core", core_cfg_def, &default_core_cfg, cfg_size(core),
+			&core_cfg)
+	) {
+		LOG(L_CRIT, "could not declare the core configuration\n");
+		goto error;
+	}
 	
 	if (init_modules() != 0) {
 		fprintf(stderr, "ERROR: error while initializing modules\n");