Преглед изворни кода

Merge remote branch 'origin/sr_3.0'

Weekly update with the latest sr_3.0 fixes.

* origin/sr_3.0:
  core: fix fixup_spve_* reuse after free
  Remove obsolete gen_ha1.
  modules_k/permissions: Increased version number of 'trusted' table
  lib/srdb1/schema/trusted.xml: forgot to increase version number
  lib/srdb1/schema/trusted.xml: increased tag length from 32 to 64 chars
  makefile: support self-installing utils, extra cfgs a.s.o.
  core: fix memleak in fixup_free*
  core: fix cfg_update() on config error 2nd try
  userblacklist(k): gcc 2.95 compile fixes
  statistics(k): minor warning in printf fmt
  siputils(k): gcc 2.95 compile fixes
  registrar(k): gcc 2.95 compile fixes
  pua_mi: gcc 2.95 compile fixes
  cfgutils(k): gcc 2.95 compile fixes
  lcr: compile & warning fixes for gcc 2.95
  db_postgres: compile fixes for gcc 2.95
  db_mysql: compile fix for gcc 2.95
  compile: don't warn on old gcc versions
  utils/sercmd: Fixed include paths also in sr_3.0 branch.

Conflicts:
	Makefile
Andrei Pelinescu-Onciul пре 16 година
родитељ
комит
a45f5ddbf3

+ 51 - 12
Makefile

@@ -339,15 +339,27 @@ cmodules=$(foreach mods,$(modules_dirs), $($(mods)))
 #modules_full_path=$(join  $(modules), $(addprefix /, $(modules_names)))
 
 
-# which utils need compilation (directory path) and which to install
-# (full path including file name)
-utils_compile=	utils/sercmd
-utils_bin_install=	# sercmd is now installed by ctl
-utils_script_install=
 
-# This is the list of files to be installed into the arch-independent
-# shared directory (by default /usr/local/share/$(MAIN_NAME))
-share_install=
+# list of utils directories that should be compiled by make utils
+C_COMPILE_UTILS=	utils/sercmd
+# list of binaries that should be installed alongside
+# (they should be created after make utils, see C_COMPILE_UTILS)
+C_INSTALL_BIN=	# sercmd is now installed by ctl
+
+# which utils know to install themselves and should be installed
+# along the core (list of utils directories)
+C_INSTALL_UTILS=
+# list of scripts that should be installed along the core 
+# (here a script is something that doesn't have a Makefile)
+C_INSTALL_SCRIPTS=
+# list of extra configs that should be installed along the core
+# Note: all the paths of the form /usr/*lib/$(CFG_NAME)/<module_dir>
+# will be updated to the directory where the modules will be installed.
+C_INSTALL_CFGS=
+# list of files that should be installed in the arch-independent 
+# directory (by default /usr/local/share/$(MAIN_NAME)))
+C_INSTALL_SHARE=
+
 
 
 
@@ -635,7 +647,7 @@ $(extra_objs):
 
 .PHONY: utils
 utils:
-	@for r in $(utils_compile) "" ; do \
+	@for r in $(C_COMPILE_UTILS) "" ; do \
 		if [ -n "$$r" ]; then \
 			$(call oecho, "" ;) \
 			$(call oecho, "" ;) \
@@ -801,6 +813,30 @@ install-cfg: $(cfg_prefix)/$(cfg_dir)
 			mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample \
 				$(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg; \
 		fi
+		# other configs
+		@for r in $(C_INSTALL_CFGS) ; do \
+			if [ -n "$$r" ]; then \
+				if [ -f "$$r" ]; then \
+					n=`basename "$$r"` ; \
+					sed $(foreach m,$(modules_dirs),\
+							-e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
+						< "$$r" \
+						> "$(cfg_prefix)/$(cfg_dir)$$n.sample" ; \
+					chmod 644 "$(cfg_prefix)/$(cfg_dir)$$n.sample" ; \
+					if [ -z "${skip_cfg_install}" -a \
+							! -f "$(cfg_prefix)/$(cfg_dir)$$n" ]; \
+					then \
+						mv -f "$(cfg_prefix)/$(cfg_dir)$$n.sample" \
+								"$(cfg_prefix)/$(cfg_dir)$$n"; \
+					fi ; \
+				else \
+					echo "ERROR: $$r not found" ; \
+					if [ ${err_fail} = 1 ] ; then \
+						exit 1; \
+					fi ; \
+				fi ; \
+			fi ; \
+		done; true
 		# radius dictionary
 		$(INSTALL_TOUCH) $(cfg_prefix)/$(cfg_dir)/dictionary.$(CFG_NAME)
 		$(INSTALL_CFG) etc/dictionary.$(CFG_NAME) $(cfg_prefix)/$(cfg_dir)
@@ -811,7 +847,7 @@ install-bin: $(bin_prefix)/$(bin_dir) $(NAME)
 
 
 install-share: $(share_prefix)/$(share_dir)
-	@for r in $(share_install) "" ; do \
+	@for r in $(C_INSTALL_SHARE) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
 				$(call try_err, $(INSTALL_TOUCH) \
@@ -835,7 +871,7 @@ install-every-module-doc: $(foreach mods,$(modules_dirs),install-$(mods)-doc)
 install-every-module-man: $(foreach mods,$(modules_dirs),install-$(mods)-man)
 
 install-utils: utils $(bin_prefix)/$(bin_dir)
-	@for r in $(utils_bin_install) "" ; do \
+	@for r in $(C_INSTALL_BIN) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
 				$(call try_err, $(INSTALL_TOUCH) \
@@ -850,7 +886,7 @@ install-utils: utils $(bin_prefix)/$(bin_dir)
 			fi ;\
 		fi ; \
 	done; true
-	@for r in $(utils_script_install) "" ; do \
+	@for r in $(C_INSTALL_SCRIPTS) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
 				$(call try_err, $(INSTALL_TOUCH) \
@@ -865,6 +901,9 @@ install-utils: utils $(bin_prefix)/$(bin_dir)
 			fi ;\
 		fi ; \
 	done; true
+	@for ut in $(C_INSTALL_UTILS) ; do \
+		$(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
+	done; true
 
 
 install-modules-all: install-every-module install-every-module-doc

+ 1 - 1
compiler_opt.h

@@ -52,7 +52,7 @@
 
 #else /* __GNUC__ */
 
-#warning "No compiler optimizations supported try gcc 4.x"
+/* #warning "No compiler optimizations supported try gcc 4.x" */
 #define likely(expr) (expr)
 #define unlikely(expr) (expr)
 

+ 2 - 2
lib/srdb1/schema/trusted.xml

@@ -9,7 +9,7 @@
 
 <table id="trusted" xmlns:db="http://docbook.org/ns/docbook">
     <name>trusted</name>
-    <version>4</version>
+    <version>5</version>
     <type db="mysql">&MYSQL_TABLE_TYPE;</type>
     <description>
         <db:para>This table is used by the permissions module to determine if a call has the appropriate permission to be established. More information about the permissions module can be found at: &KAMAILIO_MOD_DOC;permissions.html
@@ -53,7 +53,7 @@
     <column>
         <name>tag</name>
         <type>string</type>
-        <size>32</size>
+        <size>64</size>
         <null/>
         <description>Tag</description>
     </column>

+ 1 - 1
main.c

@@ -1556,6 +1556,7 @@ int main_loop()
 #endif
 		/* init cfg, but without per child callbacks support */
 		cfg_child_no_cb_init();
+		cfg_ok=1;
 
 #ifdef EXTRA_DEBUG
 		for (r=0; r<*process_count; r++){
@@ -2096,7 +2097,6 @@ try_again:
 		LOG(L_CRIT, "could not declare the core configuration\n");
 		goto error;
 	}
-	cfg_ok=1;
 #ifdef USE_TCP
 	if (tcp_register_cfg()){
 		LOG(L_CRIT, "could not register the tcp configuration\n");

+ 2 - 1
mod_fix.c

@@ -204,7 +204,6 @@ FIXUP_F2FP_T(igp_pvar_pvar, 1, 3, 1, FPARAM_INT|FPARAM_PVS, FPARAM_PVS)
 		int ret; \
 		char * bkp; \
 		fparam_t* fp; \
-		bkp=*param; \
 		if (param_no<=(no1)){ \
 			if ((ret=fix_param_types(FPARAM_PVE, param))<0){ \
 				ERR("Cannot convert function parameter %d to" #type2 "\n", \
@@ -213,6 +212,8 @@ FIXUP_F2FP_T(igp_pvar_pvar, 1, 3, 1, FPARAM_INT|FPARAM_PVS, FPARAM_PVS)
 			} else{ \
 				fp=(fparam_t*)*param; \
 				if ((ret==0) && (fp->v.pve->spec.getf==0)){ \
+					bkp=fp->orig; \
+					fp->orig=0; /* make sure orig string is not freed */ \
 					fparam_free_contents(fp); \
 					pkg_free(fp); \
 					*param=bkp; \

+ 2 - 1
modules/db_mysql/km_my_con.c

@@ -136,9 +136,10 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
  */
 void db_mysql_free_connection(struct pool_con* con)
 {
+	struct my_con * _c;
+	
 	if (!con) return;
 
-	struct my_con * _c;
 	_c = (struct my_con*) con;
 
 	if (_c->res) mysql_free_result(_c->res);

+ 2 - 1
modules/db_postgres/km_pg_con.c

@@ -108,9 +108,10 @@ struct pg_con* db_postgres_new_connection(struct db_id* id)
 void db_postgres_free_connection(struct pool_con* con)
 {
 
+	struct pg_con * _c;
+	
 	if (!con) return;
 
-	struct pg_con * _c;
 	_c = (struct pg_con*)con;
 
 	if (_c->res) {

+ 4 - 5
modules/db_postgres/pg_con.c

@@ -277,14 +277,13 @@ int pg_con_connect(db_con_t* con)
 	/* Override default notice processor */
 	PQsetNoticeProcessor(pcon->con, notice_processor, 0);
 	
-	DBG("postgres: Connected. Protocol version=%d, Server version=%d\n", 
-	    PQprotocolVersion(pcon->con),
 #ifdef HAVE_PGSERVERVERSION
-	    PQserverVersion(pcon->con)
+	DBG("postgres: Connected. Protocol version=%d, Server version=%d\n", 
+	    PQprotocolVersion(pcon->con), PQserverVersion(pcon->con));
 #else
-	    0
+	DBG("postgres: Connected. Protocol version=%d, Server version=%d\n", 
+	    PQprotocolVersion(pcon->con), 0 );
 #endif
-	    );
 
 	ret = timestamp_format(pcon->con);
 	if (ret == 1 || ret == -1) {

+ 3 - 3
modules/lcr/lcr_mod.c

@@ -399,6 +399,7 @@ static int mod_init(void)
     str s;
     unsigned short avp_flags;
     unsigned int i;
+    db1_con_t* dbh;
 
 	if(register_mi_mod(exports.name, mi_cmds)!=0)
 	{
@@ -556,7 +557,6 @@ static int mod_init(void)
     }
 
     /* Check table version */
-    db1_con_t* dbh;
     if (lcr_dbf.init==0){
 	LM_CRIT("unbound database\n");
 	return -1;
@@ -1277,7 +1277,7 @@ int reload_gws_and_lcrs(int lcr_id)
 	    first_gw = find_first_gw(gw_grps, grp_cnt, grp_id);
 	    if (first_gw == 0) {
 		LM_ERR("gw grp_id <%u> of prefix <%.*s> has no gateways\n",
-		       grp_id, prefix_len, prefix);
+		       grp_id, (int)prefix_len, prefix);
 		goto lcr_err;
 	    }
 	    if ((VAL_NULL(ROW_VALUES(row) + 3) == 1) ||
@@ -1892,7 +1892,7 @@ static int generate_uris(char *r_uri, str *r_uri_user, unsigned int *r_uri_len,
     destroy_avp(gu_avp);
 	
     LM_DBG("r_uri <%.*s>, dst_uri <%.*s>\n",
-	   *r_uri_len, r_uri, *dst_uri_len, dst_uri);
+	   (int)*r_uri_len, r_uri, (int)*dst_uri_len, dst_uri);
 
     return 1;
 }

+ 8 - 6
modules_k/cfgutils/cfgutils.c

@@ -488,11 +488,6 @@ error:
   */
 static int MD5File(char *dest, const char *file_name)
 {
-	if (!dest || !file_name) {
-		LM_ERR("invalid parameter value\n");
-		return -1;
-	}
-
 	MD5_CTX context;
 	FILE *input;
 	unsigned char buffer[32768];
@@ -500,6 +495,12 @@ static int MD5File(char *dest, const char *file_name)
 	unsigned int counter, size;
 	
 	struct stat stats;
+	
+	if (!dest || !file_name) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
+
     if (stat(file_name, &stats) != 0) {
 		LM_ERR("could not stat file %s\n", file_name);
 		return -1;
@@ -588,12 +589,13 @@ static int get_prob(struct sip_msg *bar, char *foo1, char *foo2)
 
 static int rand_event(struct sip_msg *bar, char *foo1, char *foo2)
 {
+	double tmp;
 	/* most of the time this will be disabled completly. Tis will also fix the
 	 * problem with the corner cases if rand() returned zero or RAND_MAX */
 	if ((*probability) == 0) return -1;
 	if ((*probability) == 100) return 1;
 
-	double tmp = ((double) rand() / RAND_MAX);
+	tmp = ((double) rand() / RAND_MAX);
 	LM_DBG("generated random %f\n", tmp);
 	if (tmp < ((double) (*probability) / 100)) {
 		LM_DBG("return true\n");

+ 1 - 1
modules_k/permissions/trusted.c

@@ -40,7 +40,7 @@
 #include "../../parser/parse_from.h"
 #include "../../usr_avp.h"
 
-#define TABLE_VERSION 4
+#define TABLE_VERSION 5
 
 struct trusted_list ***hash_table;     /* Pointer to current hash table pointer */
 struct trusted_list **hash_table_1;   /* Pointer to hash table 1 */

+ 2 - 1
modules_k/pua_mi/pua_mi.c

@@ -84,9 +84,10 @@ struct module_exports exports= {
  */
 static int mod_init(void)
 {
-	LM_DBG("...\n");
 	bind_pua_t bind_pua;
 	
+	LM_DBG("...\n");
+	
 	if(register_mi_mod(exports.name, mi_cmds)!=0)
 	{
 		LM_ERR("failed to register MI commands\n");

+ 1 - 2
modules_k/registrar/common.c

@@ -50,8 +50,6 @@
 int extract_aor(str* _uri, str* _a)
 {
 	static char aor_buf[MAX_AOR_LEN];
-	memset(aor_buf, 0, MAX_AOR_LEN);
-
 	str tmp;
 	struct sip_uri puri;
 	int user_len;
@@ -59,6 +57,7 @@ int extract_aor(str* _uri, str* _a)
 	struct usr_avp *avp;
 	str *uri;
 
+	memset(aor_buf, 0, MAX_AOR_LEN);
 	if (aor_avp_name.n!=0) {
 		avp = search_first_avp( aor_avp_type, aor_avp_name, &avp_val, 0);
 		if (avp && is_avp_str_val(avp)) {

+ 3 - 2
modules_k/siputils/contact_ops.c

@@ -210,6 +210,7 @@ decode_contact_header (struct sip_msg *msg,char *unused1,char *unused2)
 	
 	
 #ifdef DEBUG
+	str* ruri;
 	fprintf (stdout,"---START--------DECODE CONTACT HEADER-----------------\n");
 #endif
 
@@ -227,9 +228,9 @@ decode_contact_header (struct sip_msg *msg,char *unused1,char *unused2)
 
 #ifdef DEBUG
 	fprintf (stdout,"Using separator %c\n",separator);
-	str* ruri;
 	ruri = GET_RURI(msg);
-	fprintf (stdout,"[len = %d]New uri is->%*.s\n",ruri->len,ruri->len,ruri->s);
+	fprintf (stdout,"[len = %d]New uri is->%.*s\n",
+			ruri->len,ruri->len,ruri->s);
 	ruri = &msg->first_line.u.request.uri;
 	fprintf (stdout, "INITIAL.s=[%.*s]\n", ruri->len, ruri->s);
 #endif

+ 30 - 16
modules_k/siputils/ring.c

@@ -192,10 +192,10 @@ static void remove_timeout(unsigned int index)
 static void insert(str callid)
 {
 	unsigned int index = hash(callid.s, callid.len) & HASHTABLEMASK;
-
+	struct ring_record_t* rr;
+	
 	remove_timeout(index);
-
-	struct ring_record_t* rr = shm_malloc(sizeof(struct ring_record_t));
+	rr = shm_malloc(sizeof(struct ring_record_t));
 	assert(rr);
 
 	rr->next = NULL;
@@ -224,10 +224,11 @@ static void insert(str callid)
 static int contains(str callid)
 {
 	unsigned int index = hash(callid.s, callid.len) & HASHTABLEMASK;
+	struct ring_record_t* rr;
 
 	remove_timeout(index);
 
-	struct ring_record_t* rr = (*hashtable)[index].head;
+	rr = (*hashtable)[index].head;
 	while (rr) {
 		if (strncmp(rr->callid, callid.s, callid.len) == 0) return 1;
 		rr = rr->next;
@@ -245,25 +246,38 @@ static int conv183(struct sip_msg *msg)
 	/* content-length and content-type headers are removed */
 	char *del1_start = strstr(msg->buf, "Content-Length:");
 	char *del2_start = strstr(msg->buf, "Content-Type:");
+	char *del1_end;
+	char *del2_end;
+	char *eoh;
+	char *chunk1_start;
+	int chunk1_len;
+	char *chunk1_dst;
+	char *chunk2_start;
+	int chunk2_len;
+	char *chunk2_dst;
+	char *chunk3_start;
+	int chunk3_len;
+	char *chunk3_dst;
+	
 	if (del1_start>del2_start) {
 		char *tmp = del1_start;
 		del1_start = del2_start;
 		del2_start = tmp;
 	}
 
-	char *del1_end = NULL;
+	del1_end = NULL;
 	if (del1_start) {
 		del1_end = strstr(del1_start, "\r\n");
 		if (del1_end) del1_end+=2;
 	}
-	char *del2_end = NULL;
+	del2_end = NULL;
 	if (del2_start) {
 		del2_end = strstr(del2_start, "\r\n");
 		if (del2_end) del2_end+=2;
 	}
 
 	/* 180 message does not need session description */
-	char *eoh = strstr(msg->buf, "\r\n\r\n");
+	eoh = strstr(msg->buf, "\r\n\r\n");
 	if (eoh) eoh+=2;
 
 	if ((!del1_start) || (!del2_start) || (!del1_end) || (!del2_end) || (!eoh)) {
@@ -288,17 +302,17 @@ static int conv183(struct sip_msg *msg)
 	strncpy(msg->first_line.u.reply.reason.s, "Ringing                                           ", msg->first_line.u.reply.reason.len);
 
 	/* calculate addresses of chunks to be moved */
-	char *chunk1_start = del1_end;
-	int chunk1_len     = del2_start-del1_end;
-	char *chunk1_dst   = del1_start;
+	chunk1_start = del1_end;
+	chunk1_len     = (int)(long)(del2_start-del1_end);
+	chunk1_dst   = del1_start;
 
-	char *chunk2_start = del2_end;
-	int chunk2_len     = eoh-del2_end;
-	char *chunk2_dst   = chunk1_dst+chunk1_len;
+	chunk2_start = del2_end;
+	chunk2_len     = (int)(long)(eoh-del2_end);
+	chunk2_dst   = chunk1_dst+chunk1_len;
 
-	char *chunk3_start = "Content-Length: 0\r\n\r\n";
-	int chunk3_len     = strlen(chunk3_start);
-	char *chunk3_dst   = chunk2_dst+chunk2_len;
+	chunk3_start = "Content-Length: 0\r\n\r\n";
+	chunk3_len     = strlen(chunk3_start);
+	chunk3_dst   = chunk2_dst+chunk2_len;
 
 	// move chunks
 	memmove(chunk1_dst, chunk1_start, chunk1_len);

+ 1 - 1
modules_k/statistics/statistics.c

@@ -123,7 +123,7 @@ static int fixup_stat(void** param, int param_no)
 		/* is it pv? */
 		if (s.s[0]=='$') {
 			if (fixup_pvar_null(param, 1)!=0) {
-				LM_ERR("invalid pv %.s as parameter\n",s.s);
+				LM_ERR("invalid pv %s as parameter\n",s.s);
 				return E_CFG;
 			}
 			sopv->pv = (pv_spec_t*)(*param);

+ 4 - 4
modules_k/userblacklist/db.c

@@ -46,6 +46,10 @@ int db_build_userbl_tree(const str *username, const str *domain, const str *tabl
 	db_key_t key[2] = { &userblacklist_username_col, &userblacklist_domain_col };
 
 	db_val_t val[2];
+	db1_res_t *res;
+	int i;
+	int n = 0;
+	void *nodeflags;
 	VAL_TYPE(val) = VAL_TYPE(val + 1) = DB1_STR;
 	VAL_NULL(val) = VAL_NULL(val + 1) = 0;
 	VAL_STR(val).s = username->s;
@@ -53,10 +57,6 @@ int db_build_userbl_tree(const str *username, const str *domain, const str *tabl
 	VAL_STR(val + 1).s = domain->s;
 	VAL_STR(val + 1).len = domain->len;
 
-	db1_res_t *res;
-	int i;
-	int n = 0;
-	void *nodeflags;
 	
 	if (userblacklist_dbf.use_table(userblacklist_dbh, table) < 0) {
 		LM_ERR("cannot use table '%.*s'.\n", table->len, table->s);

+ 7 - 3
modules_k/userblacklist/userblacklist.c

@@ -380,6 +380,8 @@ static int check_blacklist_fixup(void **arg, int arg_no)
 {
 	char *table = (char *)(*arg);
 	struct dtrie_node_t *node = NULL;
+	struct check_blacklist_fs_t *new_arg;
+	
 	if (arg_no != 1) {
 		LM_ERR("wrong number of parameters\n");
 		return -1;
@@ -402,7 +404,7 @@ static int check_blacklist_fixup(void **arg, int arg_no)
 		return -1;
 	}
 
-	struct check_blacklist_fs_t *new_arg = (struct check_blacklist_fs_t*)pkg_malloc(sizeof(struct check_blacklist_fs_t));
+	new_arg = pkg_malloc(sizeof(struct check_blacklist_fs_t));
 	if (!new_arg) {
 		PKG_MEM_ERROR;
 		return -1;
@@ -475,15 +477,17 @@ static int reload_sources(void)
 {
 	int result = 0;
 	str tmp;
+	struct source_t *src;
+	int n;
 
 	/* critical section start: avoids dirty reads when updating d-tree */
 	lock_get(lock);
 
-	struct source_t *src = sources->head;
+	src = sources->head;
 	while (src) {
 		tmp.s = src->table;
 		tmp.len = strlen(src->table);
-		int n = db_reload_source(&tmp, src->dtrie_root);
+		n = db_reload_source(&tmp, src->dtrie_root);
 		if (n < 0) {
 			LM_ERR("cannot reload source from '%.*s'\n", tmp.len, tmp.s);
 			result = -1;

+ 5 - 1
sr_module.c

@@ -1195,7 +1195,7 @@ void fparam_free_contents(fparam_t* fp)
 		case FPARAM_INT:
 		case FPARAM_STR:
 			/* nothing to do */
-			return;
+			break;
 		case FPARAM_REGEX:
 			if (fp->v.regex){
 				regfree(fp->v.regex);
@@ -1231,6 +1231,10 @@ void fparam_free_contents(fparam_t* fp)
 			}
 			break;
 	}
+	if (fp->orig){
+		pkg_free(fp->orig);
+		fp->orig=0;
+	}
 }