Browse code

core/cfg: cast pointer to long to silent compiler warning

- GH #3208

Daniel-Constantin Mierla authored on 12/08/2022 12:31:48
Showing 1 changed files
... ...
@@ -284,7 +284,7 @@ static int cfg_update_defaults(cfg_group_meta_t	*meta,
284 284
 				meta->array = array;
285 285
 				clone_done = 1;
286 286
 			}
287
-			if(ginst->vars + var->offset) {
287
+			if((unsigned long)ginst->vars + var->offset) {
288 288
 				memcpy(ginst->vars + var->offset, new_val, cfg_var_size(var));
289 289
 			} else {
290 290
 				LM_ERR("invalid variable offset\n");
Browse code

core: cfg ctx - checks for valid variable offset

Daniel-Constantin Mierla authored on 09/04/2021 14:23:28
Showing 1 changed files
... ...
@@ -284,7 +284,11 @@ static int cfg_update_defaults(cfg_group_meta_t	*meta,
284 284
 				meta->array = array;
285 285
 				clone_done = 1;
286 286
 			}
287
-			memcpy(ginst->vars + var->offset, new_val, cfg_var_size(var));
287
+			if(ginst->vars + var->offset) {
288
+				memcpy(ginst->vars + var->offset, new_val, cfg_var_size(var));
289
+			} else {
290
+				LM_ERR("invalid variable offset\n");
291
+			}
288 292
 		}
289 293
 	}
290 294
 	return 0;
... ...
@@ -1122,6 +1126,10 @@ int cfg_commit(cfg_ctx_t *ctx)
1122 1126
 			}
1123 1127
 			p = group_inst->vars + changed->var->offset;
1124 1128
 		}
1129
+		if(p==NULL) {
1130
+			LM_ERR("failed to resolve valid variable offset\n");
1131
+			goto error;
1132
+		}
1125 1133
 
1126 1134
 		if (((changed->group_id_set && !changed->del_value
1127 1135
 						&& CFG_VAR_TEST_AND_SET(group_inst, changed->var))
Browse code

core: use generic PKG_MEM_ERROR, SHM_ERROR and _CRITICAL helper defines in core

- refactoring of the core to use generic PKG_MEM_ERROR, SHM_ERROR,
PKG_MEM_CRITICAL, SHM_MEM_CRITICAL and SYS_MEM_ERROR helper defines
- unify many different error messages in different spellings
- add a few missing error handler for allocation errors after (found
with a complete review of all memory allocation functions in core)
- no other functional changes, change has been reviewed two times

Henning Westerholt authored on 23/12/2018 21:31:03
Showing 1 changed files
... ...
@@ -46,7 +46,7 @@ int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb)
46 46
 	 * must be in shm mem anyway */
47 47
 	ctx = (cfg_ctx_t *)shm_malloc(sizeof(cfg_ctx_t));
48 48
 	if (!ctx) {
49
-		LM_ERR("not enough shm memory\n");
49
+		SHM_MEM_ERROR;
50 50
 		return -1;
51 51
 	}
52 52
 	memset(ctx, 0, sizeof(cfg_ctx_t));
... ...
@@ -183,7 +183,7 @@ int convert_val(unsigned int val_type, void *val,
183 183
 				if (temp_string) pkg_free(temp_string);
184 184
 				temp_string = (char *)pkg_malloc(sizeof(char) * (((str *)val)->len + 1));
185 185
 				if (!temp_string) {
186
-					LM_ERR("not enough memory\n");
186
+					PKG_MEM_ERROR;
187 187
 					return -1;
188 188
 				}
189 189
 				memcpy(temp_string, ((str *)val)->s, ((str *)val)->len);
... ...
@@ -427,7 +427,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
427 427
 				var->def->on_set_child_cb,
428 428
 				var->def->type);
429 429
 		if (!child_cb) {
430
-			LM_ERR("not enough shm memory\n");
430
+			SHM_MEM_ERROR;
431 431
 			goto error0;
432 432
 		}
433 433
 	}
... ...
@@ -558,7 +558,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
558 558
 			replaced = (void **)shm_malloc(sizeof(void *)
559 559
 					* ((old_string?1:0) + (new_array?1:0) + 1));
560 560
 			if (!replaced) {
561
-				LM_ERR("not enough shm memory\n");
561
+				SHM_MEM_ERROR;
562 562
 				goto error;
563 563
 			}
564 564
 			i = 0;
... ...
@@ -782,7 +782,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
782 782
 		if (ctx->changed_first) {
783 783
 			temp_handle = (unsigned char *)pkg_malloc(group->size);
784 784
 			if (!temp_handle) {
785
-				LM_ERR("not enough memory\n");
785
+				PKG_MEM_ERROR;
786 786
 				goto error;
787 787
 			}
788 788
 			temp_handle_created = 1;
... ...
@@ -831,7 +831,7 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
831 831
 		+ ((val_type != CFG_VAR_UNSET) ? cfg_var_size(var) : 0);
832 832
 	changed = (cfg_changed_var_t *)shm_malloc(size);
833 833
 	if (!changed) {
834
-		LM_ERR("not enough shm memory\n");
834
+		SHM_MEM_ERROR;
835 835
 		goto error;
836 836
 	}
837 837
 	memset(changed, 0, size);
... ...
@@ -1063,7 +1063,7 @@ int cfg_commit(cfg_ctx_t *ctx)
1063 1063
 		size = sizeof(void *)*(replaced_num + 1);
1064 1064
 		replaced = (void **)shm_malloc(size);
1065 1065
 		if (!replaced) {
1066
-			LM_ERR("not enough shm memory\n");
1066
+			SHM_MEM_ERROR;
1067 1067
 			goto error0;
1068 1068
 		}
1069 1069
 		memset(replaced, 0 , size);
... ...
@@ -1635,7 +1635,7 @@ int cfg_add_group_inst(cfg_ctx_t *ctx, str *group_name, unsigned int group_id)
1635 1635
 		 * they will be freed when the old block is freed */
1636 1636
 		replaced = (void **)shm_malloc(sizeof(void *) * 2);
1637 1637
 		if (!replaced) {
1638
-			LM_ERR("not enough shm memory\n");
1638
+			SHM_MEM_ERROR;
1639 1639
 			goto error;
1640 1640
 		}
1641 1641
 		replaced[0] = CFG_GROUP_META(*cfg_global, group)->array;
... ...
@@ -1740,7 +1740,7 @@ int cfg_del_group_inst(cfg_ctx_t *ctx, str *group_name, unsigned int group_id)
1740 1740
 
1741 1741
 		replaced = (void **)shm_malloc(sizeof(void *) * (num + 2));
1742 1742
 		if (!replaced) {
1743
-			LM_ERR("not enough shm memory\n");
1743
+			SHM_MEM_ERROR;
1744 1744
 			goto error;
1745 1745
 		}
1746 1746
 
Browse code

core: cfg vars - updated log macros

Daniel-Constantin Mierla authored on 26/08/2017 14:29:53
Showing 1 changed files
... ...
@@ -42,16 +42,16 @@ int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb)
42 42
 	str		gname;
43 43
 
44 44
 	/* allocate memory for the new context
45
-	Better to use shm mem, because 'changed' and 'lock'
46
-	must be in shm mem anyway */
45
+	 * Better to use shm mem, because 'changed' and 'lock'
46
+	 * must be in shm mem anyway */
47 47
 	ctx = (cfg_ctx_t *)shm_malloc(sizeof(cfg_ctx_t));
48 48
 	if (!ctx) {
49
-		LOG(L_ERR, "ERROR: cfg_register_ctx(): not enough shm memory\n");
49
+		LM_ERR("not enough shm memory\n");
50 50
 		return -1;
51 51
 	}
52 52
 	memset(ctx, 0, sizeof(cfg_ctx_t));
53 53
 	if (lock_init(&ctx->lock) == 0) {
54
-		LOG(L_ERR, "ERROR: cfg_register_ctx(): failed to init lock\n");
54
+		LM_ERR("failed to init lock\n");
55 55
 		shm_free(ctx);
56 56
 		return -1;
57 57
 	}
... ...
@@ -67,12 +67,12 @@ int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb)
67 67
 	if (on_declare_cb) {
68 68
 		ctx->on_declare_cb = on_declare_cb;
69 69
 
70
-		for (	group = cfg_group;
71
-			group;
72
-			group = group->next
73
-		) {
70
+		for (group = cfg_group;
71
+				group;
72
+				group = group->next
73
+				) {
74 74
 			/* dynamic groups are not ready, the callback
75
-			will be called later when the group is fixed-up */
75
+			 * will be called later when the group is fixed-up */
76 76
 			if (group->dynamic != CFG_GROUP_STATIC) continue;
77 77
 
78 78
 			gname.s = group->name;
... ...
@@ -89,10 +89,10 @@ void cfg_ctx_destroy(void)
89 89
 {
90 90
 	cfg_ctx_t	*ctx, *ctx2;
91 91
 
92
-	for (	ctx = cfg_ctx_list;
93
-		ctx;
94
-		ctx = ctx2
95
-	) {
92
+	for (ctx = cfg_ctx_list;
93
+			ctx;
94
+			ctx = ctx2
95
+			) {
96 96
 		ctx2 = ctx->next;
97 97
 		shm_free(ctx);
98 98
 	}
... ...
@@ -108,10 +108,10 @@ void cfg_notify_drivers(char *group_name, int group_name_len, cfg_def_t *def)
108 108
 	gname.s = group_name;
109 109
 	gname.len = group_name_len;
110 110
 
111
-	for (	ctx = cfg_ctx_list;
112
-		ctx;
113
-		ctx = ctx->next
114
-	)
111
+	for (ctx = cfg_ctx_list;
112
+			ctx;
113
+			ctx = ctx->next
114
+			)
115 115
 		if (ctx->on_declare_cb)
116 116
 			ctx->on_declare_cb(&gname, def);
117 117
 }
... ...
@@ -121,7 +121,7 @@ static char	*temp_string = NULL;
121 121
 
122 122
 /* convert the value to the requested type */
123 123
 int convert_val(unsigned int val_type, void *val,
124
-			unsigned int var_type, void **new_val)
124
+		unsigned int var_type, void **new_val)
125 125
 {
126 126
 	static str	s;
127 127
 	char		*end;
... ...
@@ -130,99 +130,95 @@ int convert_val(unsigned int val_type, void *val,
130 130
 
131 131
 	/* we have to convert from val_type to var_type */
132 132
 	switch (CFG_INPUT_MASK(var_type)) {
133
-	case CFG_INPUT_INT:
134
-		if (val_type == CFG_VAR_INT) {
135
-			*new_val = val;
136
-			break;
133
+		case CFG_INPUT_INT:
134
+			if (val_type == CFG_VAR_INT) {
135
+				*new_val = val;
136
+				break;
137 137
 
138
-		} else if (val_type == CFG_VAR_STRING) {
139
-			if (!val || (((char *)val)[0] == '\0')) {
140
-				LOG(L_ERR, "ERROR: convert_val(): "
141
-					"cannot convert NULL string value to integer\n");
142
-				return -1;
143
-			}
144
-			*new_val = (void *)(long)strtol((char *)val, &end, 10);
145
-			if (*end != '\0') {
146
-				LOG(L_ERR, "ERROR: convert_val(): "
147
-					"cannot convert string to integer '%s'\n",
148
-					(char *)val);
149
-				return -1;
150
-			}
151
-			break;
138
+			} else if (val_type == CFG_VAR_STRING) {
139
+				if (!val || (((char *)val)[0] == '\0')) {
140
+					LM_ERR("cannot convert NULL string value to integer\n");
141
+					return -1;
142
+				}
143
+				*new_val = (void *)(long)strtol((char *)val, &end, 10);
144
+				if (*end != '\0') {
145
+					LM_ERR("cannot convert string to integer '%s'\n",
146
+							(char *)val);
147
+					return -1;
148
+				}
149
+				break;
152 150
 
153
-		} else if (val_type == CFG_VAR_STR) {
154
-			if (!((str *)val)->len || !((str *)val)->s) {
155
-				LOG(L_ERR, "ERROR: convert_val(): "
156
-					"cannot convert NULL str value to integer\n");
157
-				return -1;
158
-			}
159
-			if (str2sint((str *)val, &i)) {
160
-				LOG(L_ERR, "ERROR: convert_val(): "
161
-					"cannot convert string to integer '%.*s'\n",
162
-					((str *)val)->len, ((str *)val)->s);
163
-				return -1;
151
+			} else if (val_type == CFG_VAR_STR) {
152
+				if (!((str *)val)->len || !((str *)val)->s) {
153
+					LM_ERR("cannot convert NULL str value to integer\n");
154
+					return -1;
155
+				}
156
+				if (str2sint((str *)val, &i)) {
157
+					LM_ERR("cannot convert string to integer '%.*s'\n",
158
+							((str *)val)->len, ((str *)val)->s);
159
+					return -1;
160
+				}
161
+				*new_val = (void *)(long)i;
162
+				break;
164 163
 			}
165
-			*new_val = (void *)(long)i;
166
-			break;
167
-		}
168
-		goto error;
164
+			goto error;
169 165
 
170
-	case CFG_INPUT_STRING:
171
-		if (val_type == CFG_VAR_INT) {
172
-			buf[snprintf(buf, sizeof(buf)-1, "%ld", (long)val)] = '\0';
173
-			*new_val = buf;
174
-			break;
166
+		case CFG_INPUT_STRING:
167
+			if (val_type == CFG_VAR_INT) {
168
+				buf[snprintf(buf, sizeof(buf)-1, "%ld", (long)val)] = '\0';
169
+				*new_val = buf;
170
+				break;
175 171
 
176
-		} else if (val_type == CFG_VAR_STRING) {
177
-			*new_val = val;
178
-			break;
172
+			} else if (val_type == CFG_VAR_STRING) {
173
+				*new_val = val;
174
+				break;
179 175
 
180
-		} else if (val_type == CFG_VAR_STR) {
181
-			if (!((str *)val)->s) {
182
-				*new_val = NULL;
176
+			} else if (val_type == CFG_VAR_STR) {
177
+				if (!((str *)val)->s) {
178
+					*new_val = NULL;
179
+					break;
180
+				}
181
+				/* the value may not be zero-terminated, thus,
182
+				 * a new variable has to be allocated with larger memory space */
183
+				if (temp_string) pkg_free(temp_string);
184
+				temp_string = (char *)pkg_malloc(sizeof(char) * (((str *)val)->len + 1));
185
+				if (!temp_string) {
186
+					LM_ERR("not enough memory\n");
187
+					return -1;
188
+				}
189
+				memcpy(temp_string, ((str *)val)->s, ((str *)val)->len);
190
+				temp_string[((str *)val)->len] = '\0';
191
+				*new_val = (void *)temp_string;
183 192
 				break;
184
-			}
185
-			/* the value may not be zero-terminated, thus,
186
-			a new variable has to be allocated with larger memory space */
187
-			if (temp_string) pkg_free(temp_string);
188
-			temp_string = (char *)pkg_malloc(sizeof(char) * (((str *)val)->len + 1));
189
-			if (!temp_string) {
190
-				LOG(L_ERR, "ERROR: convert_val(): not enough memory\n");
191
-				return -1;
192
-			}
193
-			memcpy(temp_string, ((str *)val)->s, ((str *)val)->len);
194
-			temp_string[((str *)val)->len] = '\0';
195
-			*new_val = (void *)temp_string;
196
-			break;
197 193
 
198
-		}
199
-		goto error;
194
+			}
195
+			goto error;
200 196
 
201
-	case CFG_INPUT_STR:
202
-		if (val_type == CFG_VAR_INT) {
203
-			s.len = snprintf(buf, sizeof(buf)-1, "%ld", (long)val);
204
-			buf[s.len] = '\0';
205
-			s.s = buf;
206
-			*new_val = (void *)&s;
207
-			break;
197
+		case CFG_INPUT_STR:
198
+			if (val_type == CFG_VAR_INT) {
199
+				s.len = snprintf(buf, sizeof(buf)-1, "%ld", (long)val);
200
+				buf[s.len] = '\0';
201
+				s.s = buf;
202
+				*new_val = (void *)&s;
203
+				break;
208 204
 
209
-		} else if (val_type == CFG_VAR_STRING) {
210
-			s.s = (char *)val;
211
-			s.len = (s.s) ? strlen(s.s) : 0;
212
-			*new_val = (void *)&s;
213
-			break;
205
+			} else if (val_type == CFG_VAR_STRING) {
206
+				s.s = (char *)val;
207
+				s.len = (s.s) ? strlen(s.s) : 0;
208
+				*new_val = (void *)&s;
209
+				break;
214 210
 
215
-		} else if (val_type == CFG_VAR_STR) {
216
-			*new_val = val;
217
-			break;			
218
-		}
219
-		goto error;
211
+			} else if (val_type == CFG_VAR_STR) {
212
+				*new_val = val;
213
+				break;
214
+			}
215
+			goto error;
220 216
 	}
221 217
 
222 218
 	return 0;
223 219
 
224 220
 error:
225
-	LOG(L_ERR, "ERROR: convert_val(): got a value with type %u, but expected %u\n",
221
+	LM_ERR("got a value with type %u, but expected %u\n",
226 222
 			val_type, CFG_INPUT_MASK(var_type));
227 223
 	return -1;
228 224
 }
... ...
@@ -240,22 +236,21 @@ static int cfg_var_size(cfg_mapping_t *var)
240 236
 {
241 237
 	switch (CFG_VAR_TYPE(var)) {
242 238
 
243
-	case CFG_VAR_INT:
244
-		return sizeof(int);
239
+		case CFG_VAR_INT:
240
+			return sizeof(int);
245 241
 
246
-	case CFG_VAR_STRING:
247
-		return sizeof(char *);
242
+		case CFG_VAR_STRING:
243
+			return sizeof(char *);
248 244
 
249
-	case CFG_VAR_STR:
250
-		return sizeof(str);
245
+		case CFG_VAR_STR:
246
+			return sizeof(str);
251 247
 
252
-	case CFG_VAR_POINTER:
253
-		return sizeof(void *);
248
+		case CFG_VAR_POINTER:
249
+			return sizeof(void *);
254 250
 
255
-	default:
256
-		LOG(L_CRIT, "BUG: cfg_var_size(): unknown type: %u\n",
257
-			CFG_VAR_TYPE(var));
258
-		return 0;
251
+		default:
252
+			LM_CRIT("unknown type: %u\n", CFG_VAR_TYPE(var));
253
+			return 0;
259 254
 	}
260 255
 }
261 256
 
... ...
@@ -264,8 +259,8 @@ static int cfg_var_size(cfg_mapping_t *var)
264 259
  * The array is cloned before a change if clone is set to 1.
265 260
  */
266 261
 static int cfg_update_defaults(cfg_group_meta_t	*meta,
267
-				cfg_group_t *group, cfg_mapping_t *var, char *new_val,
268
-				int clone)
262
+		cfg_group_t *group, cfg_mapping_t *var, char *new_val,
263
+		int clone)
269 264
 {
270 265
 	int	i, clone_done=0;
271 266
 	cfg_group_inst_t *array, *ginst;
... ...
@@ -274,7 +269,7 @@ static int cfg_update_defaults(cfg_group_meta_t	*meta,
274 269
 		return 0;
275 270
 	for (i = 0; i < meta->num; i++) {
276 271
 		ginst = (cfg_group_inst_t *)((char *)array
277
-			+ (sizeof(cfg_group_inst_t) + group->size - 1) * i);
272
+				+ (sizeof(cfg_group_inst_t) + group->size - 1) * i);
278 273
 
279 274
 		if (!CFG_VAR_TEST(ginst, var)) {
280 275
 			/* The variable uses the default value, it needs to be rewritten. */
... ...
@@ -283,13 +278,13 @@ static int cfg_update_defaults(cfg_group_meta_t	*meta,
283 278
 				if (!(array = cfg_clone_array(meta, group)))
284 279
 					return -1;
285 280
 				ginst = (cfg_group_inst_t *)translate_pointer((char *)array,
286
-								(char *)meta->array,
287
-								(char *)ginst);
281
+						(char *)meta->array,
282
+						(char *)ginst);
288 283
 				/* re-link the array to the meta-data */
289 284
 				meta->array = array;
290 285
 				clone_done = 1;
291 286
 			}
292
-			memcpy(ginst->vars + var->offset, new_val, cfg_var_size(var)); 
287
+			memcpy(ginst->vars + var->offset, new_val, cfg_var_size(var));
293 288
 		}
294 289
 	}
295 290
 	return 0;
... ...
@@ -303,7 +298,7 @@ static int cfg_update_defaults(cfg_group_meta_t	*meta,
303 298
  *   1: variable has not been found
304 299
  */
305 300
 int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name,
306
-			void *val, unsigned int val_type)
301
+		void *val, unsigned int val_type)
307 302
 {
308 303
 	int		i;
309 304
 	cfg_group_t	*group;
... ...
@@ -318,23 +313,23 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
318 313
 	unsigned char		*var_block;
319 314
 
320 315
 	/* verify the context even if we do not need it now
321
-	to make sure that a cfg driver has called the function
322
-	(very very weak security) */
316
+	 * to make sure that a cfg driver has called the function
317
+	 * (very very weak security) */
323 318
 	if (!ctx) {
324
-		LOG(L_ERR, "ERROR: cfg_set_now(): context is undefined\n");
319
+		LM_ERR("context is undefined\n");
325 320
 		return -1;
326 321
 	}
327 322
 
328 323
 	if ((val_type == CFG_VAR_UNSET) && !group_id) {
329
-		LOG(L_ERR, "ERROR: cfg_set_now(): Only group instance values can be deleted\n");
324
+		LM_ERR("Only group instance values can be deleted\n");
330 325
 		return -1;
331 326
 	}
332 327
 
333 328
 	if (group_id && !cfg_shmized) {
334
-		/* The config group has not been shmized yet,
335
-		but an additional instance of a variable needs to be added to the group.
336
-		Add this instance to the linked list of variables, they
337
-		will be fixed later. */
329
+		/* The config group has not been shmized yet, but
330
+		 * an additional instance of a variable needs to be added to the group.
331
+		 * Add this instance to the linked list of variables, they
332
+		 * will be fixed later. */
338 333
 		return new_add_var(group_name, *group_id, var_name,
339 334
 				val, val_type);
340 335
 	}
... ...
@@ -345,16 +340,15 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
345 340
 			/* The group may be dynamic which is not yet ready
346 341
 			 * before forking */
347 342
 			if ((group = cfg_lookup_group(group_name->s, group_name->len))
348
-				&& (group->dynamic == CFG_GROUP_DYNAMIC)
349
-			)
343
+					&& (group->dynamic == CFG_GROUP_DYNAMIC))
350 344
 				return cfg_set_script_var(group, var_name, val, val_type);
351 345
 		}
352 346
 		return 1;
353 347
 	}
354
-		
348
+
355 349
 	/* check whether the variable is read-only */
356 350
 	if (var->def->type & CFG_READONLY) {
357
-		LOG(L_ERR, "ERROR: cfg_set_now(): variable is read-only\n");
351
+		LM_ERR("variable is read-only\n");
358 352
 		goto error0;
359 353
 	}
360 354
 
... ...
@@ -364,59 +358,56 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
364 358
 	 * as opposed to per-process variables. Hence, it is not possible to set
365 359
 	 * the group handle temporary to another block, and then reset it back later. */
366 360
 	if (group_id
367
-		&& var->def->on_set_child_cb
368
-		&& var->def->type & CFG_CB_ONLY_ONCE
369
-	) {
370
-		LOG(L_ERR, "ERROR: cfg_set_now(): This variable does not support muliple values.\n");
361
+			&& var->def->on_set_child_cb
362
+			&& var->def->type & CFG_CB_ONLY_ONCE ) {
363
+		LM_ERR("This variable does not support muliple values.\n");
371 364
 		goto error0;
372 365
 	}
373 366
 
374 367
 	/* check whether we have to convert the type */
375 368
 	if ((val_type != CFG_VAR_UNSET)
376
-		&& convert_val(val_type, val, CFG_INPUT_TYPE(var), &v)
377
-	)
369
+			&& convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
378 370
 		goto error0;
379
-	
371
+
380 372
 	if ((val_type != CFG_VAR_UNSET)
381
-	&& (CFG_INPUT_TYPE(var) == CFG_INPUT_INT) 
382
-	&& (var->def->min || var->def->max)) {
373
+			&& (CFG_INPUT_TYPE(var) == CFG_INPUT_INT)
374
+			&& (var->def->min || var->def->max)) {
383 375
 		/* perform a simple min-max check for integers */
384 376
 		if (((int)(long)v < var->def->min)
385
-		|| ((int)(long)v > var->def->max)) {
386
-			LOG(L_ERR, "ERROR: cfg_set_now(): integer value is out of range\n");
377
+				|| ((int)(long)v > var->def->max)) {
378
+			LM_ERR("integer value is out of range\n");
387 379
 			goto error0;
388 380
 		}
389 381
 	}
390 382
 
391 383
 	if ((val_type != CFG_VAR_UNSET)
392
-		&& var->def->on_change_cb
393
-	) {
384
+			&& var->def->on_change_cb) {
394 385
 		/* Call the fixup function.
395
-		There is no need to set a temporary cfg handle,
396
-		becaue a single variable is changed */
386
+		 * There is no need to set a temporary cfg handle,
387
+		 * becaue a single variable is changed */
397 388
 		if (!group_id) {
398 389
 			var_block = *(group->handle);
399 390
 		} else {
400 391
 			if (!cfg_local) {
401
-				LOG(L_ERR, "ERROR: cfg_set_now(): Local configuration is missing\n");
392
+				LM_ERR("Local configuration is missing\n");
402 393
 				goto error0;
403 394
 			}
404 395
 			group_inst = cfg_find_group(CFG_GROUP_META(cfg_local, group),
405
-							group->size,
406
-							*group_id);
396
+					group->size,
397
+					*group_id);
407 398
 			if (!group_inst) {
408
-				LOG(L_ERR, "ERROR: cfg_set_now(): local group instance %.*s[%u] is not found\n",
409
-					group_name->len, group_name->s, *group_id);
399
+				LM_ERR("local group instance %.*s[%u] is not found\n",
400
+						group_name->len, group_name->s, *group_id);
410 401
 				goto error0;
411 402
 			}
412 403
 			var_block = group_inst->vars;
413 404
 		}
414 405
 
415 406
 		if (var->def->on_change_cb(var_block,
416
-						group_name,
417
-						var_name,
418
-						&v) < 0) {
419
-			LOG(L_ERR, "ERROR: cfg_set_now(): fixup failed\n");
407
+					group_name,
408
+					var_name,
409
+					&v) < 0) {
410
+			LM_ERR("fixup failed\n");
420 411
 			goto error0;
421 412
 		}
422 413
 
... ...
@@ -427,38 +418,38 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
427 418
 	 * switched to that instance. */
428 419
 	if (!group_id && var->def->on_set_child_cb) {
429 420
 		/* get the name of the variable from the internal struct,
430
-		because var_name may be freed before the callback needs it */
421
+		 * because var_name may be freed before the callback needs it */
431 422
 		s.s = group->name;
432 423
 		s.len = group->name_len;
433 424
 		s2.s = var->def->name;
434 425
 		s2.len = var->name_len;
435 426
 		child_cb = cfg_child_cb_new(&s, &s2,
436
-					var->def->on_set_child_cb,
437
-					var->def->type);
427
+				var->def->on_set_child_cb,
428
+				var->def->type);
438 429
 		if (!child_cb) {
439
-			LOG(L_ERR, "ERROR: cfg_set_now(): not enough shm memory\n");
430
+			LM_ERR("not enough shm memory\n");
440 431
 			goto error0;
441 432
 		}
442 433
 	}
443 434
 
444 435
 	if (cfg_shmized) {
445 436
 		/* make sure that nobody else replaces the global config
446
-		while the new one is prepared */
437
+		 * while the new one is prepared */
447 438
 		CFG_WRITER_LOCK();
448 439
 
449 440
 		if (group_id) {
450 441
 			group_inst = cfg_find_group(CFG_GROUP_META(*cfg_global, group),
451
-							group->size,
452
-							*group_id);
442
+					group->size,
443
+					*group_id);
453 444
 			if (!group_inst) {
454
-				LOG(L_ERR, "ERROR: cfg_set_now(): global group instance %.*s[%u] is not found\n",
455
-					group_name->len, group_name->s, *group_id);
445
+				LM_ERR("global group instance %.*s[%u] is not found\n",
446
+						group_name->len, group_name->s, *group_id);
456 447
 				goto error;
457 448
 			}
458 449
 			if ((val_type == CFG_VAR_UNSET) && !CFG_VAR_TEST(group_inst, var)) {
459 450
 				/* nothing to do, the variable is not set in the group instance */
460 451
 				CFG_WRITER_UNLOCK();
461
-				LOG(L_DBG, "DEBUG: cfg_set_now(): The variable is not set\n");
452
+				LM_DBG("The variable is not set\n");
462 453
 				return 0;
463 454
 			}
464 455
 			var_block = group_inst->vars;
... ...
@@ -469,7 +460,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
469 460
 
470 461
 		if (var->def->type & CFG_ATOMIC) {
471 462
 			/* atomic change is allowed, we can rewrite the value
472
-			directly in the global config */
463
+			 * directly in the global config */
473 464
 			p = var_block + var->offset;
474 465
 
475 466
 		} else {
... ...
@@ -483,8 +474,8 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
483 474
 				if (!(new_array = cfg_clone_array(CFG_GROUP_META(*cfg_global, group), group)))
484 475
 					goto error;
485 476
 				group_inst = (cfg_group_inst_t *)translate_pointer((char *)new_array,
486
-					(char *)CFG_GROUP_META(*cfg_global, group)->array,
487
-					(char *)group_inst);
477
+						(char *)CFG_GROUP_META(*cfg_global, group)->array,
478
+						(char *)group_inst);
488 479
 				var_block = group_inst->vars;
489 480
 				CFG_GROUP_META(block, group)->array = new_array;
490 481
 			} else {
... ...
@@ -500,49 +491,49 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
500 491
 		}
501 492
 	} else {
502 493
 		/* we are allowed to rewrite the value on-the-fly
503
-		The handle either points to group->vars, or to the
504
-		shared memory block (dynamic group) */
494
+		 * The handle either points to group->vars, or to the
495
+		 * shared memory block (dynamic group) */
505 496
 		p = *(group->handle) + var->offset;
506 497
 	}
507 498
 
508 499
 	if (val_type != CFG_VAR_UNSET) {
509 500
 		/* set the new value */
510 501
 		switch (CFG_VAR_TYPE(var)) {
511
-		case CFG_VAR_INT:
512
-			*(int *)p = (int)(long)v;
513
-			break;
502
+			case CFG_VAR_INT:
503
+				*(int *)p = (int)(long)v;
504
+				break;
514 505
 
515
-		case CFG_VAR_STRING:
516
-			/* clone the string to shm mem */
517
-			s.s = v;
518
-			s.len = (s.s) ? strlen(s.s) : 0;
519
-			if (cfg_clone_str(&s, &s)) goto error;
520
-			old_string = *(char **)p;
521
-			*(char **)p = s.s;
522
-			break;
506
+			case CFG_VAR_STRING:
507
+				/* clone the string to shm mem */
508
+				s.s = v;
509
+				s.len = (s.s) ? strlen(s.s) : 0;
510
+				if (cfg_clone_str(&s, &s)) goto error;
511
+				old_string = *(char **)p;
512
+				*(char **)p = s.s;
513
+				break;
523 514
 
524
-		case CFG_VAR_STR:
525
-			/* clone the string to shm mem */
526
-			s = *(str *)v;
527
-			if (cfg_clone_str(&s, &s)) goto error;
528
-			old_string = *(char **)p;
529
-			memcpy(p, &s, sizeof(str));
530
-			break;
515
+			case CFG_VAR_STR:
516
+				/* clone the string to shm mem */
517
+				s = *(str *)v;
518
+				if (cfg_clone_str(&s, &s)) goto error;
519
+				old_string = *(char **)p;
520
+				memcpy(p, &s, sizeof(str));
521
+				break;
531 522
 
532
-		case CFG_VAR_POINTER:
533
-			*(void **)p = v;
534
-			break;
523
+			case CFG_VAR_POINTER:
524
+				*(void **)p = v;
525
+				break;
535 526
 
536 527
 		}
537 528
 		if (group_inst && !CFG_VAR_TEST_AND_SET(group_inst, var))
538 529
 			old_string = NULL; /* the string is the same as the default one,
539
-						it cannot be freed */
530
+								* it cannot be freed */
540 531
 	} else {
541 532
 		/* copy the default value to the group instance */
542 533
 		if ((CFG_VAR_TYPE(var) == CFG_VAR_STRING)
543
-		|| (CFG_VAR_TYPE(var) == CFG_VAR_STR))
534
+				|| (CFG_VAR_TYPE(var) == CFG_VAR_STR))
544 535
 			old_string = *(char **)p;
545
-		memcpy(p, CFG_GROUP_DATA(*cfg_global, group) + var->offset, cfg_var_size(var)); 
536
+		memcpy(p, CFG_GROUP_DATA(*cfg_global, group) + var->offset, cfg_var_size(var));
546 537
 
547 538
 		CFG_VAR_TEST_AND_RESET(group_inst, var);
548 539
 	}
... ...
@@ -550,11 +541,11 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
550 541
 	if (cfg_shmized) {
551 542
 		if (!group_inst) {
552 543
 			/* the default value is changed, the copies of this value
553
-			need to be also updated */
544
+			 * need to be also updated */
554 545
 			if (cfg_update_defaults(CFG_GROUP_META(block ? block : *cfg_global, group),
555 546
 						group, var, p,
556 547
 						block ? 1 : 0) /* clone if needed */
557
-			)
548
+					)
558 549
 				goto error;
559 550
 			if (block && (CFG_GROUP_META(block, group)->array != CFG_GROUP_META(*cfg_global, group)->array))
560 551
 				new_array = CFG_GROUP_META(block, group)->array;
... ...
@@ -562,12 +553,12 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
562 553
 
563 554
 		if (old_string || new_array) {
564 555
 			/* prepare the array of the replaced strings,
565
-			and replaced group instances,
566
-			they will be freed when the old block is freed */
556
+			 * and replaced group instances,
557
+			 * they will be freed when the old block is freed */
567 558
 			replaced = (void **)shm_malloc(sizeof(void *)
568 559
 					* ((old_string?1:0) + (new_array?1:0) + 1));
569 560
 			if (!replaced) {
570
-				LOG(L_ERR, "ERROR: cfg_set_now(): not enough shm memory\n");
561
+				LM_ERR("not enough shm memory\n");
571 562
 				goto error;
572 563
 			}
573 564
 			i = 0;
... ...
@@ -575,7 +566,7 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
575 566
 				replaced[i] = old_string;
576 567
 				i++;
577 568
 			}
578
-			if (new_array) {	
569
+			if (new_array) {
579 570
 				replaced[i] = CFG_GROUP_META(*cfg_global, group)->array;
580 571
 				i++;
581 572
 			}
... ...
@@ -590,52 +581,46 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
590 581
 			shm_free(old_string);
591 582
 
592 583
 		/* flag the variable because there is no need
593
-		to shmize it again */
584
+		 * to shmize it again */
594 585
 		var->flag |= cfg_var_shmized;
595 586
 
596 587
 		/* the global config does not have to be replaced,
597
-		but the child callback has to be installed, otherwise the
598
-		child processes will miss the change */
588
+		 * but the child callback has to be installed, otherwise the
589
+		 * child processes will miss the change */
599 590
 		if (child_cb)
600 591
 			cfg_install_child_cb(child_cb, child_cb);
601 592
 	}
602 593
 
603 594
 	if (val_type == CFG_VAR_INT)
604
-		LOG(L_INFO, "INFO: cfg_set_now(): %.*s.%.*s "
605
-			"has been changed to %d\n",
606
-			group_name->len, group_name->s,
607
-			var_name->len, var_name->s,
608
-			(int)(long)val);
595
+		LM_INFO("%.*s.%.*s has been changed to %d\n",
596
+				group_name->len, group_name->s,
597
+				var_name->len, var_name->s,
598
+				(int)(long)val);
609 599
 
610 600
 	else if (val_type == CFG_VAR_STRING)
611
-		LOG(L_INFO, "INFO: cfg_set_now(): %.*s.%.*s "
612
-			"has been changed to \"%s\"\n",
613
-			group_name->len, group_name->s,
614
-			var_name->len, var_name->s,
615
-			(char *)val);
601
+		LM_INFO("%.*s.%.*s has been changed to \"%s\"\n",
602
+				group_name->len, group_name->s,
603
+				var_name->len, var_name->s,
604
+				(char *)val);
616 605
 
617 606
 	else if (val_type == CFG_VAR_STR)
618
-		LOG(L_INFO, "INFO: cfg_set_now(): %.*s.%.*s "
619
-			"has been changed to \"%.*s\"\n",
620
-			group_name->len, group_name->s,
621
-			var_name->len, var_name->s,
622
-			((str *)val)->len, ((str *)val)->s);
607
+		LM_INFO("%.*s.%.*s has been changed to \"%.*s\"\n",
608
+				group_name->len, group_name->s,
609
+				var_name->len, var_name->s,
610
+				((str *)val)->len, ((str *)val)->s);
623 611
 
624 612
 	else if (val_type == CFG_VAR_UNSET)
625
-		LOG(L_INFO, "INFO: cfg_set_now(): %.*s.%.*s "
626
-			"has been deleted\n",
627
-			group_name->len, group_name->s,
628
-			var_name->len, var_name->s);
613
+		LM_INFO("%.*s.%.*s has been deleted\n",
614
+				group_name->len, group_name->s,
615
+				var_name->len, var_name->s);
629 616
 
630 617
 	else
631
-		LOG(L_INFO, "INFO: cfg_set_now(): %.*s.%.*s "
632
-			"has been changed\n",
633
-			group_name->len, group_name->s,
634
-			var_name->len, var_name->s);
618
+		LM_INFO("%.*s.%.*s has been changed\n",
619
+				group_name->len, group_name->s,
620
+				var_name->len, var_name->s);
635 621
 
636 622
 	if (group_id)
637
-		LOG(L_INFO, "INFO: cfg_set_now(): group id = %u\n",
638
-			*group_id);
623
+		LM_INFO("group id = %u\n", *group_id);
639 624
 
640 625
 	convert_val_cleanup();
641 626
 	return 0;
... ...
@@ -648,7 +633,7 @@ error:
648 633
 	if (replaced) shm_free(replaced);
649 634
 
650 635
 error0:
651
-	LOG(L_ERR, "ERROR: cfg_set_now(): failed to set the variable: %.*s.%.*s\n",
636
+	LM_ERR("failed to set the variable: %.*s.%.*s\n",
652 637
 			group_name->len, group_name->s,
653 638
 			var_name->len, var_name->s);
654 639
 
... ...
@@ -658,35 +643,36 @@ error0:
658 643
 }
659 644
 
660 645
 /* wrapper function for cfg_set_now */
661
-int cfg_set_now_int(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name,
662
-			int val)
646
+int cfg_set_now_int(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
647
+		str *var_name, int val)
663 648
 {
664 649
 	return cfg_set_now(ctx, group_name, group_id, var_name,
665
-				(void *)(long)val, CFG_VAR_INT);
650
+			(void *)(long)val, CFG_VAR_INT);
666 651
 }
667 652
 
668 653
 /* wrapper function for cfg_set_now */
669
-int cfg_set_now_string(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name,
670
-			char *val)
654
+int cfg_set_now_string(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
655
+		str *var_name, char *val)
671 656
 {
672 657
 	return cfg_set_now(ctx, group_name, group_id, var_name,
673
-				(void *)val, CFG_VAR_STRING);
658
+			(void *)val, CFG_VAR_STRING);
674 659
 }
675 660
 
676 661
 /* wrapper function for cfg_set_now */
677
-int cfg_set_now_str(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name,
678
-			str *val)
662
+int cfg_set_now_str(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
663
+		str *var_name, str *val)
679 664
 {
680 665
 	return cfg_set_now(ctx, group_name, group_id, var_name,
681
-				(void *)val, CFG_VAR_STR);
666
+			(void *)val, CFG_VAR_STR);
682 667
 }
683 668
 
684 669
 /* Delete a variable from the group instance.
685 670
  * wrapper function for cfg_set_now */
686
-int cfg_del_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name)
671
+int cfg_del_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
672
+		str *var_name)
687 673
 {
688 674
 	return cfg_set_now(ctx, group_name, group_id, var_name,
689
-				NULL, CFG_VAR_UNSET);
675
+			NULL, CFG_VAR_UNSET);
690 676
 }
691 677
 
692 678
 /* sets the value of a variable but does not commit the change
... ...
@@ -696,8 +682,8 @@ int cfg_del_now(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *va
696 682
  *  -1: error
697 683
  *   1: variable has not been found
698 684
  */
699
-int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str *var_name,
700
-			void *val, unsigned int val_type)
685
+int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id,
686
+		str *var_name, void *val, unsigned int val_type)
701 687
 {
702 688
 	cfg_group_t	*group;
703 689
 	cfg_mapping_t	*var;
... ...
@@ -712,17 +698,17 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, unsigned int *group_id, str
712 698
 
713 699
 	if (!cfg_shmized)
714 700
 		/* the cfg has not been shmized yet, there is no
715
-		point in registering the change and committing it later */
701
+		 * point in registering the change and committing it later */
716 702
 		return cfg_set_now(ctx, group_name, group_id, var_name,
717
-					val, val_type);