Browse Source

core: make database version table name configurable from script

When kamailio is part of a bigger project and is sharing its database with
it, it is nice to have a less generic table name than "version".

Also usefull when upgrading kamailio, where the new version has (backwards
compatibel) changes in the database definition. If each kamailio version uses
its own version table, they can all use the same database.
Alex Hermann 12 years ago
parent
commit
8fb8b261fa
6 changed files with 13 additions and 2 deletions
  1. 2 0
      cfg.lex
  2. 5 0
      cfg.y
  3. 1 0
      config.h
  4. 1 0
      globals.h
  5. 3 2
      lib/srdb1/db.c
  6. 1 0
      main.c

+ 2 - 0
cfg.lex

@@ -496,6 +496,7 @@ MAX_WLOOPS		"max_while_loops"
 PVBUFSIZE		"pv_buffer_size"
 PVBUFSLOTS		"pv_buffer_slots"
 HTTP_REPLY_HACK		"http_reply_hack"
+VERSION_TABLE_CFG		"version_table"
 
 /* stun config variables */
 STUN_REFRESH_INTERVAL "stun_refresh_interval"
@@ -973,6 +974,7 @@ IMPORTFILE      "import_file"
 									return PVBUFSLOTS; }
 <INITIAL>{HTTP_REPLY_HACK}		{	count(); yylval.strval=yytext;
 									return HTTP_REPLY_HACK; }
+<INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}

+ 5 - 0
cfg.y

@@ -561,6 +561,7 @@ extern char *finame;
 %token PVBUFSIZE
 %token PVBUFSLOTS
 %token HTTP_REPLY_HACK
+%token VERSION_TABLE_CFG
 %token CFG_DESCRIPTION
 %token SERVER_ID
 %token LATENCY_LOG
@@ -984,6 +985,10 @@ assign_stm:
 	| CORELOG EQUAL error { yyerror("int value expected"); }
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
+	| VERSION_TABLE_CFG EQUAL STRING { version_table.s=$3;
+			version_table.len=strlen(version_table.s);
+	}
+	| VERSION_TABLE_CFG EQUAL error { yyerror("string value expected"); }
 	| USER EQUAL STRING     {
 		if (shm_initialized())
 			yyerror("user must be before any modparam or the"

+ 1 - 0
config.h

@@ -206,6 +206,7 @@
 #endif
 
 #define VERSION_TABLE "version"			/*!< table holding versions of other ser tables */
+#define VERSION_TABLE_LEN (sizeof(VERSION_TABLE) - 1)
 #define VERSION_COLUMN "table_version"		/*!< Column holding version number in version table */
 #define TABLENAME_COLUMN "table_name"		/*!< Column holding module name in version table */
 

+ 1 - 0
globals.h

@@ -129,6 +129,7 @@ extern char* chroot_dir;
 extern char* working_dir;
 extern int sr_auto_aliases;
 extern int sr_msg_time;
+extern str version_table;
 
 #ifdef USE_MCAST
 extern int mcast_loopback;

+ 3 - 2
lib/srdb1/db.c

@@ -61,6 +61,7 @@
 #include "../../sr_module.h"
 #include "../../mem/mem.h"
 #include "../../ut.h"
+#include "../../globals.h"
 #include "db_cap.h"
 #include "db_id.h"
 #include "db_pool.h"
@@ -372,7 +373,7 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab
 	db_val_t val[1];
 	db1_res_t* res = NULL;
 	db_val_t* ver = 0;
-	str version = str_init(VERSION_TABLE);
+	str *version = &version_table;
 	str tmp1 = str_init(TABLENAME_COLUMN);
 	str tmp2 = str_init(VERSION_COLUMN);
 	int ret;
@@ -382,7 +383,7 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab
 		return -1;
 	}
 
-	if (dbf->use_table(connection, &version) < 0) {
+	if (dbf->use_table(connection, version) < 0) {
 		LM_ERR("error while changing table\n");
 		return -1;
 	}

+ 1 - 0
main.c

@@ -397,6 +397,7 @@ int sip_warning = 0;
 int server_signature=1;
 str server_hdr = {SERVER_HDR, SERVER_HDR_LEN};
 str user_agent_hdr = {USER_AGENT, USER_AGENT_LEN};
+str version_table = {VERSION_TABLE, VERSION_TABLE_LEN};
 /* should ser try to locate outbound interface on multihomed
  * host? by default not -- too expensive
  */