Browse code

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 authored on 08/01/2013 18:09:48
Showing 6 changed files
... ...
@@ -496,6 +496,7 @@ MAX_WLOOPS		"max_while_loops"
496 496
 PVBUFSIZE		"pv_buffer_size"
497 497
 PVBUFSLOTS		"pv_buffer_slots"
498 498
 HTTP_REPLY_HACK		"http_reply_hack"
499
+VERSION_TABLE_CFG		"version_table"
499 500
 
500 501
 /* stun config variables */
501 502
 STUN_REFRESH_INTERVAL "stun_refresh_interval"
... ...
@@ -973,6 +974,7 @@ IMPORTFILE      "import_file"
973 973
 									return PVBUFSLOTS; }
974 974
 <INITIAL>{HTTP_REPLY_HACK}		{	count(); yylval.strval=yytext;
975 975
 									return HTTP_REPLY_HACK; }
976
+<INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
976 977
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
977 978
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
978 979
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
... ...
@@ -561,6 +561,7 @@ extern char *finame;
561 561
 %token PVBUFSIZE
562 562
 %token PVBUFSLOTS
563 563
 %token HTTP_REPLY_HACK
564
+%token VERSION_TABLE_CFG
564 565
 %token CFG_DESCRIPTION
565 566
 %token SERVER_ID
566 567
 %token LATENCY_LOG
... ...
@@ -984,6 +985,10 @@ assign_stm:
984 984
 	| CORELOG EQUAL error { yyerror("int value expected"); }
985 985
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
986 986
 	| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
987
+	| VERSION_TABLE_CFG EQUAL STRING { version_table.s=$3;
988
+			version_table.len=strlen(version_table.s);
989
+	}
990
+	| VERSION_TABLE_CFG EQUAL error { yyerror("string value expected"); }
987 991
 	| USER EQUAL STRING     {
988 992
 		if (shm_initialized())
989 993
 			yyerror("user must be before any modparam or the"
... ...
@@ -206,6 +206,7 @@
206 206
 #endif
207 207
 
208 208
 #define VERSION_TABLE "version"			/*!< table holding versions of other ser tables */
209
+#define VERSION_TABLE_LEN (sizeof(VERSION_TABLE) - 1)
209 210
 #define VERSION_COLUMN "table_version"		/*!< Column holding version number in version table */
210 211
 #define TABLENAME_COLUMN "table_name"		/*!< Column holding module name in version table */
211 212
 
... ...
@@ -129,6 +129,7 @@ extern char* chroot_dir;
129 129
 extern char* working_dir;
130 130
 extern int sr_auto_aliases;
131 131
 extern int sr_msg_time;
132
+extern str version_table;
132 133
 
133 134
 #ifdef USE_MCAST
134 135
 extern int mcast_loopback;
... ...
@@ -61,6 +61,7 @@
61 61
 #include "../../sr_module.h"
62 62
 #include "../../mem/mem.h"
63 63
 #include "../../ut.h"
64
+#include "../../globals.h"
64 65
 #include "db_cap.h"
65 66
 #include "db_id.h"
66 67
 #include "db_pool.h"
... ...
@@ -372,7 +373,7 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab
372 372
 	db_val_t val[1];
373 373
 	db1_res_t* res = NULL;
374 374
 	db_val_t* ver = 0;
375
-	str version = str_init(VERSION_TABLE);
375
+	str *version = &version_table;
376 376
 	str tmp1 = str_init(TABLENAME_COLUMN);
377 377
 	str tmp2 = str_init(VERSION_COLUMN);
378 378
 	int ret;
... ...
@@ -382,7 +383,7 @@ int db_table_version(const db_func_t* dbf, db1_con_t* connection, const str* tab
382 382
 		return -1;
383 383
 	}
384 384
 
385
-	if (dbf->use_table(connection, &version) < 0) {
385
+	if (dbf->use_table(connection, version) < 0) {
386 386
 		LM_ERR("error while changing table\n");
387 387
 		return -1;
388 388
 	}
... ...
@@ -397,6 +397,7 @@ int sip_warning = 0;
397 397
 int server_signature=1;
398 398
 str server_hdr = {SERVER_HDR, SERVER_HDR_LEN};
399 399
 str user_agent_hdr = {USER_AGENT, USER_AGENT_LEN};
400
+str version_table = {VERSION_TABLE, VERSION_TABLE_LEN};
400 401
 /* should ser try to locate outbound interface on multihomed
401 402
  * host? by default not -- too expensive
402 403
  */