Browse code

usrloc: connect to db for main process in PROC_POSTCHILDINIT child init

Daniel-Constantin Mierla authored on 09/05/2022 07:05:18
Showing 1 changed files
... ...
@@ -358,6 +358,16 @@ static int mod_init(void)
358 358
 	}
359 359
 
360 360
 	/* Shall we use database ? */
361
+	switch (ul_db_mode) {
362
+		case DB_ONLY:
363
+		case WRITE_THROUGH:
364
+		case WRITE_BACK:
365
+		/*
366
+		 * register the need to be called post-fork of all children
367
+		 * with the special rank PROC_POSTCHILDINIT
368
+		 */
369
+		ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT);
370
+	}
361 371
 	if (ul_db_mode != NO_DB) { /* Yes */
362 372
 		if (db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */
363 373
 			LM_ERR("failed to bind database module\n");
... ...
@@ -452,14 +462,14 @@ static int child_init(int _rank)
452 462
 		case WRITE_THROUGH:
453 463
 			/* connect to db only from SIP workers, TIMER and MAIN processes,
454 464
 			 *  and RPC processes */
455
-			if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_MAIN
465
+			if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT
456 466
 					 && _rank!=PROC_RPC)
457 467
 				return 0;
458 468
 			break;
459 469
 		case WRITE_BACK:
460 470
 			/* connect to db only from TIMER (for flush), from MAIN (for
461 471
 			 * final flush() and from child 1 for preload */
462
-			if (_rank!=PROC_TIMER && _rank!=PROC_MAIN && _rank!=PROC_SIPINIT)
472
+			if (_rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT && _rank!=PROC_SIPINIT)
463 473
 				return 0;
464 474
 			break;
465 475
 		case DB_READONLY:
Browse code

usrloc: removed unrelated comment with is_main

- was not even used

Daniel-Constantin Mierla authored on 10/01/2022 17:35:58
Showing 1 changed files
... ...
@@ -46,7 +46,7 @@
46 46
 #include "../../core/rpc_lookup.h"
47 47
 #include "../../core/timer.h"     /* register_timer */
48 48
 #include "../../core/timer_proc.h" /* register_sync_timer */
49
-#include "../../core/globals.h"   /* is_main */
49
+#include "../../core/globals.h"
50 50
 #include "../../core/ut.h"        /* str_init */
51 51
 #include "../../core/utils/sruid.h"
52 52
 #include "dlist.h"           /* register_udomain */
Browse code

usrloc: added db_clean_tcp parameter

- if set, tcp contacts are deleted before loading location table at
start time
- it is very common that end points use only tcp client connections, on
restart those connections are lost and corresponding contacts are
useless

Daniel-Constantin Mierla authored on 10/09/2021 09:12:01
Showing 1 changed files
... ...
@@ -176,6 +176,7 @@ int ul_desc_time_order = 0;				/*!< By default do not enable timestamp ordering
176 176
 int ul_handle_lost_tcp = 0;				/*!< By default do not remove contacts before expiration time */
177 177
 int ul_close_expired_tcp = 0;				/*!< By default do not close TCP connections for expired contacts */
178 178
 int ul_skip_remote_socket = 0;				/*!< By default do not skip remote socket */
179
+int ul_db_clean_tcp = 0;				/*!< Clean TCP/TLS/WSS contacts in DB before loading records */
179 180
 
180 181
 int ul_fetch_rows = 2000;				/*!< number of rows to fetch from result */
181 182
 int ul_hash_size = 10;
... ...
@@ -263,6 +264,7 @@ static param_export_t params[] = {
263 264
 	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
264 265
 	{"ka_logmsg",           PARAM_STR, &ul_ka_logmsg},
265 266
 	{"load_rank",           PARAM_INT, &ul_load_rank},
267
+	{"db_clean_tcp",        PARAM_INT, &ul_db_clean_tcp},
266 268
 	{0, 0, 0}
267 269
 };
268 270
 
Browse code

usrloc: new parameter load_rank

- allows to set the rank of the child to load the location records
- default: 1 (PROC_SIPINIT) - preserse the current behaviour

Daniel-Constantin Mierla authored on 15/03/2021 11:48:55
Showing 1 changed files
... ...
@@ -116,6 +116,7 @@ int ul_db_raw_fetch_type = 0;
116 116
 int ul_rm_expired_delay = 0;
117 117
 int ul_version_table = 1;
118 118
 
119
+int ul_load_rank = PROC_SIPINIT;
119 120
 str ul_xavp_contact_name = {0};
120 121
 
121 122
 str ul_ka_from = str_init("sip:server@kamailio.org");
... ...
@@ -261,6 +262,7 @@ static param_export_t params[] = {
261 262
 	{"ka_timeout",          PARAM_INT, &ul_keepalive_timeout},
262 263
 	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
263 264
 	{"ka_logmsg",           PARAM_STR, &ul_ka_logmsg},
265
+	{"load_rank",           PARAM_INT, &ul_load_rank},
264 266
 	{0, 0, 0}
265 267
 };
266 268
 
... ...
@@ -472,7 +474,7 @@ static int child_init(int _rank)
472 474
 		return -1;
473 475
 	}
474 476
 	/* _rank==PROC_SIPINIT is used even when fork is disabled */
475
-	if (_rank==PROC_SIPINIT && ul_db_mode!=DB_ONLY && ul_db_load) {
477
+	if (_rank==ul_load_rank && ul_db_mode!=DB_ONLY && ul_db_load) {
476 478
 		/* if cache is used, populate domains from DB */
477 479
 		for(ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
478 480
 			if (preload_udomain(ul_dbh, ptr->d) < 0) {
Browse code

usrloc: export modparam to set keepalive timeout

- variable was not exported by the module for internal keepalive
mechanism

Daniel-Constantin Mierla authored on 11/09/2020 20:00:38
Showing 1 changed files
... ...
@@ -258,6 +258,7 @@ static param_export_t params[] = {
258 258
 	{"ka_domain",           PARAM_STR, &ul_ka_domain},
259 259
 	{"ka_method",           PARAM_STR, &ul_ka_method},
260 260
 	{"ka_filter",           PARAM_INT, &ul_ka_filter},
261
+	{"ka_timeout",          PARAM_INT, &ul_keepalive_timeout},
261 262
 	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
262 263
 	{"ka_logmsg",           PARAM_STR, &ul_ka_logmsg},
263 264
 	{0, 0, 0}
Browse code

usrloc: export the ka_logmsg parameter

- GH #2440

Daniel-Constantin Mierla authored on 17/08/2020 09:44:09
Showing 1 changed files
... ...
@@ -259,6 +259,7 @@ static param_export_t params[] = {
259 259
 	{"ka_method",           PARAM_STR, &ul_ka_method},
260 260
 	{"ka_filter",           PARAM_INT, &ul_ka_filter},
261 261
 	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
262
+	{"ka_logmsg",           PARAM_STR, &ul_ka_logmsg},
262 263
 	{0, 0, 0}
263 264
 };
264 265
 
Browse code

usrloc: use ul prefix for global param variables

Daniel-Constantin Mierla authored on 01/05/2020 12:47:55
Showing 1 changed files
... ...
@@ -134,28 +134,28 @@ sruid_t _ul_sruid;
134 134
  * Module parameters and their default values
135 135
  */
136 136
 
137
-str ruid_col        = str_init(RUID_COL); 		/*!< Name of column containing record unique id */
138
-str user_col        = str_init(USER_COL); 		/*!< Name of column containing usernames */
139
-str domain_col      = str_init(DOMAIN_COL); 	/*!< Name of column containing domains */
140
-str contact_col     = str_init(CONTACT_COL);	/*!< Name of column containing contact addresses */
141
-str expires_col     = str_init(EXPIRES_COL);	/*!< Name of column containing expires values */
142
-str q_col           = str_init(Q_COL);			/*!< Name of column containing q values */
143
-str callid_col      = str_init(CALLID_COL);		/*!< Name of column containing callid string */
144
-str cseq_col        = str_init(CSEQ_COL);		/*!< Name of column containing cseq values */
145
-str flags_col       = str_init(FLAGS_COL);		/*!< Name of column containing internal flags */
146
-str cflags_col      = str_init(CFLAGS_COL);		/*!< Name of column containing contact flags */
147
-str user_agent_col  = str_init(USER_AGENT_COL);	/*!< Name of column containing user agent string */
148
-str received_col    = str_init(RECEIVED_COL);	/*!< Name of column containing transport info of REGISTER */
149
-str path_col        = str_init(PATH_COL);		/*!< Name of column containing the Path header */
150
-str sock_col        = str_init(SOCK_COL);		/*!< Name of column containing the received socket */
151
-str methods_col     = str_init(METHODS_COL);	/*!< Name of column containing the supported methods */
152
-str instance_col    = str_init(INSTANCE_COL);	/*!< Name of column containing the SIP instance value */
153
-str reg_id_col      = str_init(REG_ID_COL);		/*!< Name of column containing the reg-id value */
154
-str last_mod_col    = str_init(LAST_MOD_COL);	/*!< Name of column containing the last modified date */
155
-str srv_id_col      = str_init(SRV_ID_COL);		/*!< Name of column containing the server id value */
156
-str con_id_col      = str_init(CON_ID_COL);		/*!< Name of column containing the connection id value */
157
-str keepalive_col   = str_init(KEEPALIVE_COL);	/*!< Name of column containing the keepalive value */
158
-str partition_col   = str_init(PARTITION_COL);	/*!< Name of column containing the partition value */
137
+str ul_ruid_col        = str_init(RUID_COL); 		/*!< Name of column containing record unique id */
138
+str ul_user_col        = str_init(USER_COL); 		/*!< Name of column containing usernames */
139
+str ul_domain_col      = str_init(DOMAIN_COL); 	/*!< Name of column containing domains */
140
+str ul_contact_col     = str_init(CONTACT_COL);	/*!< Name of column containing contact addresses */
141
+str ul_expires_col     = str_init(EXPIRES_COL);	/*!< Name of column containing expires values */
142
+str ul_q_col           = str_init(Q_COL);			/*!< Name of column containing q values */
143
+str ul_callid_col      = str_init(CALLID_COL);		/*!< Name of column containing callid string */
144
+str ul_cseq_col        = str_init(CSEQ_COL);		/*!< Name of column containing cseq values */
145
+str ul_flags_col       = str_init(FLAGS_COL);		/*!< Name of column containing internal flags */
146
+str ul_cflags_col      = str_init(CFLAGS_COL);		/*!< Name of column containing contact flags */
147
+str ul_user_agent_col  = str_init(USER_AGENT_COL);	/*!< Name of column containing user agent string */
148
+str ul_received_col    = str_init(RECEIVED_COL);	/*!< Name of column containing transport info of REGISTER */
149
+str ul_path_col        = str_init(PATH_COL);		/*!< Name of column containing the Path header */
150
+str ul_sock_col        = str_init(SOCK_COL);		/*!< Name of column containing the received socket */
151
+str ul_methods_col     = str_init(METHODS_COL);	/*!< Name of column containing the supported methods */
152
+str ul_instance_col    = str_init(INSTANCE_COL);	/*!< Name of column containing the SIP instance value */
153
+str ul_reg_id_col      = str_init(REG_ID_COL);		/*!< Name of column containing the reg-id value */
154
+str ul_last_mod_col    = str_init(LAST_MOD_COL);	/*!< Name of column containing the last modified date */
155
+str ul_srv_id_col      = str_init(SRV_ID_COL);		/*!< Name of column containing the server id value */
156
+str ul_con_id_col      = str_init(CON_ID_COL);		/*!< Name of column containing the connection id value */
157
+str ul_keepalive_col   = str_init(KEEPALIVE_COL);	/*!< Name of column containing the keepalive value */
158
+str ul_partition_col   = str_init(PARTITION_COL);	/*!< Name of column containing the partition value */
159 159
 
160 160
 str ulattrs_user_col   = str_init(ULATTRS_USER_COL);   /*!< Name of column containing username */
161 161
 str ulattrs_domain_col = str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */
... ...
@@ -165,16 +165,16 @@ str ulattrs_atype_col  = str_init(ULATTRS_ATYPE_COL);  /*!< Name of column conta
165 165
 str ulattrs_avalue_col = str_init(ULATTRS_AVALUE_COL); /*!< Name of column containing attribute value */
166 166
 str ulattrs_last_mod_col = str_init(ULATTRS_LAST_MOD_COL);	/*!< Name of column containing the last modified date */
167 167
 
168
-str db_url          = str_init(DEFAULT_DB_URL);	/*!< Database URL */
169
-int timer_interval  = 60;				/*!< Timer interval in seconds */
170
-int db_mode         = 0;				/*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
171
-int db_load         = 1;				/*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */
172
-int db_insert_update = 0;				/*!< Database : update on duplicate key instead of error */
173
-int use_domain      = 0;				/*!< Whether usrloc should use domain part of aor */
174
-int desc_time_order = 0;				/*!< By default do not enable timestamp ordering */
175
-int handle_lost_tcp = 0;				/*!< By default do not remove contacts before expiration time */
176
-int close_expired_tcp = 0;				/*!< By default do not close TCP connections for expired contacts */
177
-int skip_remote_socket = 0;				/*!< By default do not skip remote socket */
168
+str ul_db_url          = str_init(DEFAULT_DB_URL);	/*!< Database URL */
169
+int ul_timer_interval  = 60;				/*!< Timer interval in seconds */
170
+int ul_db_mode         = 0;				/*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
171
+int ul_db_load         = 1;				/*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */
172
+int ul_db_insert_update = 0;				/*!< Database : update on duplicate key instead of error */
173
+int ul_use_domain      = 0;				/*!< Whether usrloc should use domain part of aor */
174
+int ul_desc_time_order = 0;				/*!< By default do not enable timestamp ordering */
175
+int ul_handle_lost_tcp = 0;				/*!< By default do not remove contacts before expiration time */
176
+int ul_close_expired_tcp = 0;				/*!< By default do not close TCP connections for expired contacts */
177
+int ul_skip_remote_socket = 0;				/*!< By default do not skip remote socket */
178 178
 
179 179
 int ul_fetch_rows = 2000;				/*!< number of rows to fetch from result */
180 180
 int ul_hash_size = 10;
... ...
@@ -182,8 +182,8 @@ int ul_db_insert_null = 0;
182 182
 int ul_db_timer_clean = 0;
183 183
 
184 184
 /* flags */
185
-unsigned int nat_bflag = (unsigned int)-1;
186
-unsigned int init_flag = 0;
185
+unsigned int ul_nat_bflag = (unsigned int)-1;
186
+unsigned int ul_init_flag = 0;
187 187
 
188 188
 db1_con_t* ul_dbh = 0; /* Database connection handle */
189 189
 db_func_t ul_dbf;
... ...
@@ -204,42 +204,42 @@ static cmd_export_t cmds[] = {
204 204
  * Exported parameters
205 205
  */
206 206
 static param_export_t params[] = {
207
-	{"ruid_column",         PARAM_STR, &ruid_col      },
208
-	{"user_column",         PARAM_STR, &user_col      },
209
-	{"domain_column",       PARAM_STR, &domain_col    },
210
-	{"contact_column",      PARAM_STR, &contact_col   },
211
-	{"expires_column",      PARAM_STR, &expires_col   },
212
-	{"q_column",            PARAM_STR, &q_col         },
213
-	{"callid_column",       PARAM_STR, &callid_col    },
214
-	{"cseq_column",         PARAM_STR, &cseq_col      },
215
-	{"flags_column",        PARAM_STR, &flags_col     },
216
-	{"cflags_column",       PARAM_STR, &cflags_col    },
217
-	{"db_url",              PARAM_STR, &db_url        },
218
-	{"timer_interval",      INT_PARAM, &timer_interval  },
219
-	{"db_mode",             INT_PARAM, &db_mode         },
220
-	{"db_load",             INT_PARAM, &db_load         },
221
-	{"db_insert_update",    INT_PARAM, &db_insert_update },
222
-	{"use_domain",          INT_PARAM, &use_domain      },
223
-	{"desc_time_order",     INT_PARAM, &desc_time_order },
224
-	{"user_agent_column",   PARAM_STR, &user_agent_col},
225
-	{"received_column",     PARAM_STR, &received_col  },
226
-	{"path_column",         PARAM_STR, &path_col      },
227
-	{"socket_column",       PARAM_STR, &sock_col      },
228
-	{"methods_column",      PARAM_STR, &methods_col   },
229
-	{"instance_column",     PARAM_STR, &instance_col  },
230
-	{"reg_id_column",       PARAM_STR, &reg_id_col    },
231
-	{"server_id_column",    PARAM_STR, &srv_id_col    },
232
-	{"connection_id_column",PARAM_STR, &con_id_col    },
233
-	{"keepalive_column",    PARAM_STR, &keepalive_col },
234
-	{"partition_column",    PARAM_STR, &partition_col },
207
+	{"ruid_column",         PARAM_STR, &ul_ruid_col      },
208
+	{"user_column",         PARAM_STR, &ul_user_col      },
209
+	{"domain_column",       PARAM_STR, &ul_domain_col    },
210
+	{"contact_column",      PARAM_STR, &ul_contact_col   },
211
+	{"expires_column",      PARAM_STR, &ul_expires_col   },
212
+	{"q_column",            PARAM_STR, &ul_q_col         },
213
+	{"callid_column",       PARAM_STR, &ul_callid_col    },
214
+	{"cseq_column",         PARAM_STR, &ul_cseq_col      },
215
+	{"flags_column",        PARAM_STR, &ul_flags_col     },
216
+	{"cflags_column",       PARAM_STR, &ul_cflags_col    },
217
+	{"db_url",              PARAM_STR, &ul_db_url        },
218
+	{"timer_interval",      INT_PARAM, &ul_timer_interval  },
219
+	{"db_mode",             INT_PARAM, &ul_db_mode         },
220
+	{"db_load",             INT_PARAM, &ul_db_load         },
221
+	{"db_insert_update",    INT_PARAM, &ul_db_insert_update },
222
+	{"use_domain",          INT_PARAM, &ul_use_domain      },
223
+	{"desc_time_order",     INT_PARAM, &ul_desc_time_order },
224
+	{"user_agent_column",   PARAM_STR, &ul_user_agent_col},
225
+	{"received_column",     PARAM_STR, &ul_received_col  },
226
+	{"path_column",         PARAM_STR, &ul_path_col      },
227
+	{"socket_column",       PARAM_STR, &ul_sock_col      },
228
+	{"methods_column",      PARAM_STR, &ul_methods_col   },
229
+	{"instance_column",     PARAM_STR, &ul_instance_col  },
230
+	{"reg_id_column",       PARAM_STR, &ul_reg_id_col    },
231
+	{"server_id_column",    PARAM_STR, &ul_srv_id_col    },
232
+	{"connection_id_column",PARAM_STR, &ul_con_id_col    },
233
+	{"keepalive_column",    PARAM_STR, &ul_keepalive_col },
234
+	{"partition_column",    PARAM_STR, &ul_partition_col },
235 235
 	{"matching_mode",       INT_PARAM, &ul_matching_mode },
236
-	{"cseq_delay",          INT_PARAM, &cseq_delay      },
236
+	{"cseq_delay",          INT_PARAM, &ul_cseq_delay      },
237 237
 	{"fetch_rows",          INT_PARAM, &ul_fetch_rows   },
238 238
 	{"hash_size",           INT_PARAM, &ul_hash_size    },
239
-	{"nat_bflag",           INT_PARAM, &nat_bflag       },
240
-	{"handle_lost_tcp",     INT_PARAM, &handle_lost_tcp },
241
-	{"close_expired_tcp",   INT_PARAM, &close_expired_tcp },
242
-	{"skip_remote_socket",  INT_PARAM, &skip_remote_socket },
239
+	{"nat_bflag",           INT_PARAM, &ul_nat_bflag       },
240
+	{"handle_lost_tcp",     INT_PARAM, &ul_handle_lost_tcp },
241
+	{"close_expired_tcp",   INT_PARAM, &ul_close_expired_tcp },
242
+	{"skip_remote_socket",  INT_PARAM, &ul_skip_remote_socket },
243 243
 	{"preload",             PARAM_STRING|USE_FUNC_PARAM, (void*)ul_preload_param},
244 244
 	{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
245 245
 	{"timer_procs",         INT_PARAM, &ul_timer_procs},
... ...
@@ -292,7 +292,7 @@ static int mod_init(void)
292 292
 	udomain_t* d;
293 293
 
294 294
 	if(ul_rm_expired_delay!=0) {
295
-		if(db_mode != DB_ONLY) {
295
+		if(ul_db_mode != DB_ONLY) {
296 296
 			LM_ERR("rm expired delay feature is available for db only mode\n");
297 297
 			return -1;
298 298
 		}
... ...
@@ -308,7 +308,7 @@ static int mod_init(void)
308 308
 
309 309
 #ifdef STATISTICS
310 310
 	/* register statistics */
311
-	if (register_module_stats( exports.name, mod_stats)!=0 ) {
311
+	if (register_module_stats(exports.name, mod_stats)!=0 ) {
312 312
 		LM_ERR("failed to register core statistics\n");
313 313
 		return -1;
314 314
 	}
... ...
@@ -338,22 +338,22 @@ static int mod_init(void)
338 338
 
339 339
 	/* Register cache timer */
340 340
 	if(ul_timer_procs<=0) {
341
-		if (timer_interval > 0) {
342
-			register_timer(ul_core_timer, 0, timer_interval);
341
+		if (ul_timer_interval > 0) {
342
+			register_timer(ul_core_timer, 0, ul_timer_interval);
343 343
 		}
344 344
 	} else {
345 345
 		register_sync_timers(ul_timer_procs);
346 346
 	}
347 347
 
348 348
 	/* init the callbacks list */
349
-	if ( init_ulcb_list() < 0) {
349
+	if (init_ulcb_list() < 0) {
350 350
 		LM_ERR("usrloc/callbacks initialization failed\n");
351 351
 		return -1;
352 352
 	}
353 353
 
354 354
 	/* Shall we use database ? */
355
-	if (db_mode != NO_DB) { /* Yes */
356
-		if (db_bind_mod(&db_url, &ul_dbf) < 0) { /* Find database module */
355
+	if (ul_db_mode != NO_DB) { /* Yes */
356
+		if (db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */
357 357
 			LM_ERR("failed to bind database module\n");
358 358
 			return -1;
359 359
 		}
... ...
@@ -367,22 +367,22 @@ static int mod_init(void)
367 367
 			return -1;
368 368
 		}
369 369
 	}
370
-	if(db_mode==WRITE_THROUGH || db_mode==WRITE_BACK) {
370
+	if(ul_db_mode==WRITE_THROUGH || ul_db_mode==WRITE_BACK) {
371 371
 		if(ul_db_timer_clean!=0) {
372
-			if(sr_wtimer_add(ul_db_clean_timer, 0, timer_interval)<0) {
372
+			if(sr_wtimer_add(ul_db_clean_timer, 0, ul_timer_interval)<0) {
373 373
 				LM_ERR("failed to add db clean timer routine\n");
374 374
 				return -1;
375 375
 			}
376 376
 		}
377 377
 	}
378 378
 
379
-	if (nat_bflag==(unsigned int)-1) {
380
-		nat_bflag = 0;
381
-	} else if ( nat_bflag>=8*sizeof(nat_bflag) ) {
382
-		LM_ERR("bflag index (%d) too big!\n", nat_bflag);
379
+	if (ul_nat_bflag==(unsigned int)-1) {
380
+		ul_nat_bflag = 0;
381
+	} else if (ul_nat_bflag>=8*sizeof(ul_nat_bflag) ) {
382
+		LM_ERR("bflag index (%d) too big!\n", ul_nat_bflag);
383 383
 		return -1;
384 384
 	} else {
385
-		nat_bflag = 1<<nat_bflag;
385
+		ul_nat_bflag = 1<<ul_nat_bflag;
386 386
 	}
387 387
 
388 388
 	for(i=0; i<ul_preload_index; i++) {
... ...
@@ -392,11 +392,11 @@ static int mod_init(void)
392 392
 		}
393 393
 	}
394 394
 
395
-	if (handle_lost_tcp && db_mode == DB_ONLY) {
395
+	if (ul_handle_lost_tcp && ul_db_mode == DB_ONLY) {
396 396
 		LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");
397 397
 	}
398 398
 
399
-	if(db_mode != DB_ONLY) {
399
+	if(ul_db_mode != DB_ONLY) {
400 400
 		ul_set_xavp_contact_clone(1);
401 401
 	}
402 402
 
... ...
@@ -413,7 +413,7 @@ static int mod_init(void)
413 413
 		}
414 414
 	}
415 415
 
416
-	init_flag = 1;
416
+	ul_init_flag = 1;
417 417
 	return 0;
418 418
 }
419 419
 
... ...
@@ -431,7 +431,7 @@ static int child_init(int _rank)
431 431
 		for(i=0; i<ul_timer_procs; i++)
432 432
 		{
433 433
 			if(fork_sync_timer(PROC_TIMER, "USRLOC Timer", 1 /*socks flag*/,
434
-					ul_local_timer, (void*)(long)i, timer_interval /*sec*/)<0) {
434
+					ul_local_timer, (void*)(long)i, ul_timer_interval /*sec*/)<0) {
435 435
 				LM_ERR("failed to start timer routine as process\n");
436 436
 				return -1; /* error */
437 437
 			}
... ...
@@ -439,7 +439,7 @@ static int child_init(int _rank)
439 439
 	}
440 440
 
441 441
 	/* connecting to DB ? */
442
-	switch (db_mode) {
442
+	switch (ul_db_mode) {
443 443
 		case NO_DB:
444 444
 			return 0;
445 445
 		case DB_ONLY:
... ...
@@ -458,19 +458,19 @@ static int child_init(int _rank)
458 458
 			break;
459 459
 		case DB_READONLY:
460 460
 			/* connect to db only from child 1 for preload */
461
-			db_load=1; /* we always load from the db in this mode */
461
+			ul_db_load=1; /* we always load from the db in this mode */
462 462
 			if(_rank!=PROC_SIPINIT)
463 463
 				return 0;
464 464
 			break;
465 465
 	}
466 466
 
467
-	ul_dbh = ul_dbf.init(&db_url); /* Get a database connection per child */
467
+	ul_dbh = ul_dbf.init(&ul_db_url); /* Get a database connection per child */
468 468
 	if (!ul_dbh) {
469 469
 		LM_ERR("child(%d): failed to connect to database\n", _rank);
470 470
 		return -1;
471 471
 	}
472 472
 	/* _rank==PROC_SIPINIT is used even when fork is disabled */
473
-	if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY && db_load) {
473
+	if (_rank==PROC_SIPINIT && ul_db_mode!=DB_ONLY && ul_db_load) {
474 474
 		/* if cache is used, populate domains from DB */
475 475
 		for(ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
476 476
 			if (preload_udomain(ul_dbh, ptr->d) < 0) {
Browse code

usrloc: default keepalive log message prints remote address in socket format

- more compact than sip uri format

Daniel-Constantin Mierla authored on 29/03/2020 15:25:28
Showing 1 changed files
... ...
@@ -124,7 +124,7 @@ str ul_ka_method = str_init("OPTIONS");
124 124
 int ul_ka_mode = 0;
125 125
 int ul_ka_filter = 0;
126 126
 int ul_ka_loglevel = 255;
127
-str ul_ka_logmsg = str_init(" to-uri: [$tu] src-uri: [$su]");
127
+str ul_ka_logmsg = str_init(" to-uri: [$tu] remote-addr: [$sas]");
128 128
 pv_elem_t *ul_ka_logfmt = NULL;
129 129
 
130 130
 /* sruid to get internal uid for mi/rpc commands */
Browse code

usrloc: fexible logging for roundtrip details

- new params ka_loglevel and ka_logmsg

Daniel-Constantin Mierla authored on 28/03/2020 08:56:47
Showing 1 changed files
... ...
@@ -123,6 +123,9 @@ str ul_ka_domain = str_init("kamailio.org");
123 123
 str ul_ka_method = str_init("OPTIONS");
124 124
 int ul_ka_mode = 0;
125 125
 int ul_ka_filter = 0;
126
+int ul_ka_loglevel = 255;
127
+str ul_ka_logmsg = str_init(" to-uri: [$tu] src-uri: [$su]");
128
+pv_elem_t *ul_ka_logfmt = NULL;
126 129
 
127 130
 /* sruid to get internal uid for mi/rpc commands */
128 131
 sruid_t _ul_sruid;
... ...
@@ -255,6 +258,7 @@ static param_export_t params[] = {
255 258
 	{"ka_domain",           PARAM_STR, &ul_ka_domain},
256 259
 	{"ka_method",           PARAM_STR, &ul_ka_method},
257 260
 	{"ka_filter",           PARAM_INT, &ul_ka_filter},
261
+	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
258 262
 	{0, 0, 0}
259 263
 };
260 264
 
... ...
@@ -396,9 +400,17 @@ static int mod_init(void)
396 400
 		ul_set_xavp_contact_clone(1);
397 401
 	}
398 402
 
399
-	/* set max partition number for timers processing of db records */
400
-	if((ul_ka_mode != ULKA_NONE) && (ul_timer_procs > 1)) {
401
-		ul_set_max_partition((unsigned int)ul_timer_procs);
403
+	if(ul_ka_mode != ULKA_NONE) {
404
+		/* set max partition number for timers processing of db records */
405
+		if (ul_timer_procs > 1) {
406
+			ul_set_max_partition((unsigned int)ul_timer_procs);
407
+		}
408
+		if(ul_ka_logmsg.len > 0) {
409
+			if(pv_parse_format(&ul_ka_logmsg, &ul_ka_logfmt) < 0) {
410
+				LM_ERR("failed parsing ka log message format\n");
411
+				return -1;
412
+			}
413
+		}
402 414
 	}
403 415
 
404 416
 	init_flag = 1;
Browse code

usrloc: internal keepalive support for db only mode

- new parameter ka_filter to enable server_id filtering of db records
processed for keepalive

Daniel-Constantin Mierla authored on 27/03/2020 16:54:00
Showing 1 changed files
... ...
@@ -122,6 +122,7 @@ str ul_ka_from = str_init("sip:server@kamailio.org");
122 122
 str ul_ka_domain = str_init("kamailio.org");
123 123
 str ul_ka_method = str_init("OPTIONS");
124 124
 int ul_ka_mode = 0;
125
+int ul_ka_filter = 0;
125 126
 
126 127
 /* sruid to get internal uid for mi/rpc commands */
127 128
 sruid_t _ul_sruid;
... ...
@@ -253,6 +254,7 @@ static param_export_t params[] = {
253 254
 	{"ka_from",             PARAM_STR, &ul_ka_from},
254 255
 	{"ka_domain",           PARAM_STR, &ul_ka_domain},
255 256
 	{"ka_method",           PARAM_STR, &ul_ka_method},
257
+	{"ka_filter",           PARAM_INT, &ul_ka_filter},
256 258
 	{0, 0, 0}
257 259
 };
258 260
 
... ...
@@ -394,6 +396,11 @@ static int mod_init(void)
394 396
 		ul_set_xavp_contact_clone(1);
395 397
 	}
396 398
 
399
+	/* set max partition number for timers processing of db records */
400
+	if((ul_ka_mode != ULKA_NONE) && (ul_timer_procs > 1)) {
401
+		ul_set_max_partition((unsigned int)ul_timer_procs);
402
+	}
403
+
397 404
 	init_flag = 1;
398 405
 	return 0;
399 406
 }
Browse code

usrloc: global root var for domains list renamed to _ksr_ul_root

Daniel-Constantin Mierla authored on 27/03/2020 12:58:56
Showing 1 changed files
... ...
@@ -453,7 +453,7 @@ static int child_init(int _rank)
453 453
 	/* _rank==PROC_SIPINIT is used even when fork is disabled */
454 454
 	if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY && db_load) {
455 455
 		/* if cache is used, populate domains from DB */
456
-		for( ptr=root ; ptr ; ptr=ptr->next) {
456
+		for(ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
457 457
 			if (preload_udomain(ul_dbh, ptr->d) < 0) {
458 458
 				LM_ERR("child(%d): failed to preload domain '%.*s'\n",
459 459
 						_rank, ptr->name.len, ZSW(ptr->name.s));
Browse code

usrloc: options to do keepalive for natted or udp contacts only

- variants to make it emulate the current nathelper keepalive, which is
done for UDP only
- usrloc keepalive can be sent for all types of contacts

Daniel-Constantin Mierla authored on 27/03/2020 09:16:23
Showing 1 changed files
... ...
@@ -251,8 +251,8 @@ static param_export_t params[] = {
251 251
 	{"version_table",       PARAM_INT, &ul_version_table},
252 252
 	{"ka_mode",             PARAM_INT, &ul_ka_mode},
253 253
 	{"ka_from",             PARAM_STR, &ul_ka_from},
254
-	{"ka_domain",             PARAM_STR, &ul_ka_domain},
255
-	{"ka_method",             PARAM_STR, &ul_ka_method},
254
+	{"ka_domain",           PARAM_STR, &ul_ka_domain},
255
+	{"ka_method",           PARAM_STR, &ul_ka_method},
256 256
 	{0, 0, 0}
257 257
 };
258 258
 
Browse code

usrloc: process keepalive response

Daniel-Constantin Mierla authored on 26/03/2020 20:02:09
Showing 1 changed files
... ...
@@ -55,6 +55,7 @@
55 55
 #include "ucontact.h"        /* update_ucontact */
56 56
 #include "ul_rpc.h"
57 57
 #include "ul_callback.h"
58
+#include "ul_keepalive.h"
58 59
 #include "usrloc.h"
59 60
 
60 61
 MODULE_VERSION
... ...
@@ -96,6 +97,7 @@ static void ul_core_timer(unsigned int ticks, void* param);  /*!< Core timer han
96 97
 static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */
97 98
 static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer handler */
98 99
 static int child_init(int rank);                    /*!< Per-child init function */
100
+static int ul_sip_reply_received(sip_msg_t *msg); /*!< SIP response handling */
99 101
 
100 102
 #define UL_PRELOAD_SIZE	8
101 103
 static char* ul_preload_list[UL_PRELOAD_SIZE];
... ...
@@ -268,7 +270,7 @@ struct module_exports exports = {
268 270
 	params,          /*!< exported parameters */
269 271
 	0,               /*!< exported rpc functions */
270 272
 	0,               /*!< exported pseudo-variables */
271
-	0,               /*!< response handling function */
273
+	ul_sip_reply_received, /*!< response handling function */
272 274
 	mod_init,        /*!< module init function */
273 275
 	child_init,      /*!< child init function */
274 276
 	destroy          /*!< destroy function */
... ...
@@ -484,6 +486,17 @@ static void destroy(void)
484 486
 	destroy_ulcb_list();
485 487
 }
486 488
 
489
+/*! \brief
490
+ * Callback to handle the SIP replies
491
+ */
492
+static int ul_sip_reply_received(sip_msg_t *msg)
493
+{
494
+	if(ul_ka_mode == 0) {
495
+		return 1;
496
+	}
497
+	ul_ka_reply_received(msg);
498
+	return 1;
499
+}
487 500
 
488 501
 /*! \brief
489 502
  * Core timer handler
Browse code

usrloc: ability to send keep alive requests

- GH #2223
- work in progress

Daniel-Constantin Mierla authored on 26/03/2020 15:18:17
Showing 1 changed files
... ...
@@ -116,6 +116,11 @@ int ul_version_table = 1;
116 116
 
117 117
 str ul_xavp_contact_name = {0};
118 118
 
119
+str ul_ka_from = str_init("sip:server@kamailio.org");
120
+str ul_ka_domain = str_init("kamailio.org");
121
+str ul_ka_method = str_init("OPTIONS");
122
+int ul_ka_mode = 0;
123
+
119 124
 /* sruid to get internal uid for mi/rpc commands */
120 125
 sruid_t _ul_sruid;
121 126
 
... ...
@@ -242,6 +247,10 @@ static param_export_t params[] = {
242 247
 	{"db_timer_clean",      PARAM_INT, &ul_db_timer_clean},
243 248
 	{"rm_expired_delay",    PARAM_INT, &ul_rm_expired_delay},
244 249
 	{"version_table",       PARAM_INT, &ul_version_table},
250
+	{"ka_mode",             PARAM_INT, &ul_ka_mode},
251
+	{"ka_from",             PARAM_STR, &ul_ka_from},
252
+	{"ka_domain",             PARAM_STR, &ul_ka_domain},
253
+	{"ka_method",             PARAM_STR, &ul_ka_method},
245 254
 	{0, 0, 0}
246 255
 };
247 256
 
Browse code

usrloc: coherent coding style in mod init function

Daniel-Constantin Mierla authored on 20/02/2020 14:50:58
Showing 1 changed files
... ...
@@ -285,8 +285,9 @@ static int mod_init(void)
285 285
 				ul_rm_expired_delay);
286 286
 		ul_rm_expired_delay = 0;
287 287
 	}
288
-	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
288
+	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) {
289 289
 		return -1;
290
+	}
290 291
 
291 292
 #ifdef STATISTICS
292 293
 	/* register statistics */
... ...
@@ -296,16 +297,16 @@ static int mod_init(void)
296 297
 	}
297 298
 #endif
298 299
 
299
-	if (rpc_register_array(ul_rpc)!=0)
300
-	{
300
+	if (rpc_register_array(ul_rpc)!=0) {
301 301
 		LM_ERR("failed to register RPC commands\n");
302 302
 		return -1;
303 303
 	}
304 304
 
305
-	if(ul_hash_size<=1)
305
+	if(ul_hash_size<=1) {
306 306
 		ul_hash_size = 512;
307
-	else
307
+	} else {
308 308
 		ul_hash_size = 1<<ul_hash_size;
309
+	}
309 310
 
310 311
 	/* check matching mode */
311 312
 	switch (ul_matching_mode) {
... ...
@@ -319,13 +320,13 @@ static int mod_init(void)
319 320
 	}
320 321
 
321 322
 	/* Register cache timer */
322
-	if(ul_timer_procs<=0)
323
-	{
324
-		if (timer_interval > 0)
323
+	if(ul_timer_procs<=0) {
324
+		if (timer_interval > 0) {
325 325
 			register_timer(ul_core_timer, 0, timer_interval);
326
-	}
327
-	else
326
+		}
327
+	} else {
328 328
 		register_sync_timers(ul_timer_procs);
329
+	}
329 330
 
330 331
 	/* init the callbacks list */
331 332
 	if ( init_ulcb_list() < 0) {
... ...
@@ -374,8 +375,9 @@ static int mod_init(void)
374 375
 		}
375 376
 	}
376 377
 
377
-	if (handle_lost_tcp && db_mode == DB_ONLY)
378
+	if (handle_lost_tcp && db_mode == DB_ONLY) {
378 379
 		LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");
380
+	}
379 381
 
380 382
 	if(db_mode != DB_ONLY) {
381 383
 		ul_set_xavp_contact_clone(1);
Browse code

usrloc: updated with relocation of lib/srutils to core/utils

Daniel-Constantin Mierla authored on 21/01/2020 13:41:52
Showing 1 changed files
... ...
@@ -48,7 +48,7 @@
48 48
 #include "../../core/timer_proc.h" /* register_sync_timer */
49 49
 #include "../../core/globals.h"   /* is_main */
50 50
 #include "../../core/ut.h"        /* str_init */
51
-#include "../../lib/srutils/sruid.h"
51
+#include "../../core/utils/sruid.h"
52 52
 #include "dlist.h"           /* register_udomain */
53 53
 #include "udomain.h"         /* {insert,delete,get,release}_urecord */
54 54
 #include "urecord.h"         /* {insert,delete,get}_ucontact */
Browse code

usrloc: clone xavp list in contact struct in memory mode

Daniel-Constantin Mierla authored on 28/05/2019 06:44:32
Showing 1 changed files
... ...
@@ -377,8 +377,11 @@ static int mod_init(void)
377 377
 	if (handle_lost_tcp && db_mode == DB_ONLY)
378 378
 		LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");
379 379
 
380
-	init_flag = 1;
380
+	if(db_mode != DB_ONLY) {
381
+		ul_set_xavp_contact_clone(1);
382
+	}
381 383
 
384
+	init_flag = 1;
382 385
 	return 0;
383 386
 }
384 387
 
Browse code

usrloc: updated to the new mod interface

Daniel-Constantin Mierla authored on 27/09/2018 21:18:16 • Victor Seva committed on 28/09/2018 11:03:26
Showing 1 changed files
... ...
@@ -253,18 +253,16 @@ stat_export_t mod_stats[] = {
253 253
 
254 254
 
255 255
 struct module_exports exports = {
256
-	"usrloc",
256
+	"usrloc",        /*!< module name */
257 257
 	DEFAULT_DLFLAGS, /*!< dlopen flags */
258
-	cmds,       /*!< Exported functions */
259
-	params,     /*!< Export parameters */
260
-	mod_stats,  /*!< exported statistics */
261
-	0,          /*!< exported MI functions */
262
-	0,          /*!< exported pseudo-variables */
263
-	0,          /*!< extra processes */
264
-	mod_init,   /*!< Module initialization function */
265
-	0,          /*!< Response function */
266
-	destroy,    /*!< Destroy function */
267
-	child_init  /*!< Child initialization function */
258
+	cmds,            /*!< exported functions */
259
+	params,          /*!< exported parameters */
260
+	0,               /*!< exported rpc functions */
261
+	0,               /*!< exported pseudo-variables */
262
+	0,               /*!< response handling function */
263
+	mod_init,        /*!< module init function */
264
+	child_init,      /*!< child init function */
265
+	destroy          /*!< destroy function */
268 266
 };
269 267
 
270 268
 
Browse code

usrloc: new parameter version_table

- set it to 0 to disable checking the version for location table

Daniel-Constantin Mierla authored on 14/06/2018 08:27:42
Showing 1 changed files
... ...
@@ -112,6 +112,7 @@ int ul_db_ops_ruid = 1;
112 112
 int ul_expires_type = 0;
113 113
 int ul_db_raw_fetch_type = 0;
114 114
 int ul_rm_expired_delay = 0;
115
+int ul_version_table = 1;
115 116
 
116 117
 str ul_xavp_contact_name = {0};
117 118
 
... ...
@@ -240,6 +241,7 @@ static param_export_t params[] = {
240 241
 	{"server_id_filter",    PARAM_INT, &ul_db_srvid},
241 242
 	{"db_timer_clean",      PARAM_INT, &ul_db_timer_clean},
242 243
 	{"rm_expired_delay",    PARAM_INT, &ul_rm_expired_delay},
244
+	{"version_table",       PARAM_INT, &ul_version_table},
243 245
 	{0, 0, 0}
244 246
 };
245 247
 
Browse code

usrloc: renamed global var matching_mode to ul_matching_mode

- avoid exports conflict with the other usrloc alternative modules

Daniel-Constantin Mierla authored on 30/04/2018 10:51:07
Showing 1 changed files
... ...
@@ -220,7 +220,7 @@ static param_export_t params[] = {
220 220
 	{"connection_id_column",PARAM_STR, &con_id_col    },
221 221
 	{"keepalive_column",    PARAM_STR, &keepalive_col },
222 222
 	{"partition_column",    PARAM_STR, &partition_col },
223
-	{"matching_mode",       INT_PARAM, &matching_mode   },
223
+	{"matching_mode",       INT_PARAM, &ul_matching_mode },
224 224
 	{"cseq_delay",          INT_PARAM, &cseq_delay      },
225 225
 	{"fetch_rows",          INT_PARAM, &ul_fetch_rows   },
226 226
 	{"hash_size",           INT_PARAM, &ul_hash_size    },
... ...
@@ -308,14 +308,14 @@ static int mod_init(void)
308 308
 		ul_hash_size = 1<<ul_hash_size;
309 309
 
310 310
 	/* check matching mode */
311
-	switch (matching_mode) {
311
+	switch (ul_matching_mode) {
312 312
 		case CONTACT_ONLY:
313 313
 		case CONTACT_CALLID:
314 314
 		case CONTACT_PATH:
315 315
 		case CONTACT_CALLID_ONLY:
316 316
 			break;
317 317
 		default:
318
-			LM_ERR("invalid matching mode %d\n", matching_mode);
318
+			LM_ERR("invalid matching mode %d\n", ul_matching_mode);
319 319
 	}
320 320
 
321 321
 	/* Register cache timer */
Browse code

usrloc: cleanup by server_id. (#1480)

* usrloc: cleanup by server_id.

* usrloc: reverted README file changes.

* usrloc: moved server_id db request assignment under conditional command.

Konstantin authored on 12/03/2018 12:25:18 • Daniel-Constantin Mierla committed on 12/03/2018 12:25:18
Showing 1 changed files
... ...
@@ -176,7 +176,7 @@ unsigned int init_flag = 0;
176 176
 db1_con_t* ul_dbh = 0; /* Database connection handle */
177 177
 db_func_t ul_dbf;
178 178
 
179
-/* filter on load by server id */
179
+/* filter on load and during cleanup by server id */
180 180
 unsigned int ul_db_srvid = 0;
181 181
 
182 182
 /*! \brief
Browse code

usrloc: new parameter rm_expired_delay

- set how many seconds to delay the removal of an expired record
- for now works only in DB_ONLY mode

Daniel-Constantin Mierla authored on 19/01/2018 10:05:31
Showing 1 changed files
... ...
@@ -111,6 +111,7 @@ int ul_keepalive_timeout = 0;
111 111
 int ul_db_ops_ruid = 1;
112 112
 int ul_expires_type = 0;
113 113
 int ul_db_raw_fetch_type = 0;
114
+int ul_rm_expired_delay = 0;
114 115
 
115 116
 str ul_xavp_contact_name = {0};
116 117
 
... ...
@@ -238,6 +239,7 @@ static param_export_t params[] = {
238 239
 	{"db_insert_null",      PARAM_INT, &ul_db_insert_null},
239 240
 	{"server_id_filter",    PARAM_INT, &ul_db_srvid},
240 241
 	{"db_timer_clean",      PARAM_INT, &ul_db_timer_clean},
242
+	{"rm_expired_delay",    PARAM_INT, &ul_rm_expired_delay},
241 243
 	{0, 0, 0}
242 244
 };
243 245
 
... ...
@@ -272,6 +274,17 @@ static int mod_init(void)
272 274
 	int i;
273 275
 	udomain_t* d;
274 276
 
277
+	if(ul_rm_expired_delay!=0) {
278
+		if(db_mode != DB_ONLY) {
279
+			LM_ERR("rm expired delay feature is available for db only mode\n");
280
+			return -1;
281
+		}
282
+	}
283
+	if(ul_rm_expired_delay<0) {
284
+		LM_WARN("rm expired delay value is negative (%d) - setting it to 0\n",
285
+				ul_rm_expired_delay);
286
+		ul_rm_expired_delay = 0;
287
+	}
275 288
 	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
276 289
 		return -1;
277 290
 
Browse code

usrloc: partion column name can be set via modparam

Oyvind Kolbu authored on 15/12/2017 11:11:04 • Daniel-Constantin Mierla committed on 15/12/2017 11:11:04
Showing 1 changed files
... ...
@@ -218,6 +218,7 @@ static param_export_t params[] = {
218 218
 	{"server_id_column",    PARAM_STR, &srv_id_col    },
219 219
 	{"connection_id_column",PARAM_STR, &con_id_col    },
220 220
 	{"keepalive_column",    PARAM_STR, &keepalive_col },
221
+	{"partition_column",    PARAM_STR, &partition_col },
221 222
 	{"matching_mode",       INT_PARAM, &matching_mode   },
222 223
 	{"cseq_delay",          INT_PARAM, &cseq_delay      },
223 224
 	{"fetch_rows",          INT_PARAM, &ul_fetch_rows   },
Browse code

usrloc: adding params

db_load: enable/disable loading from the database on mod_init
db_insert_update: insert into table, update on duplicate key

Julien Chavanton authored on 18/03/2017 20:16:15
Showing 1 changed files
... ...
@@ -155,6 +155,8 @@ str ulattrs_last_mod_col = str_init(ULATTRS_LAST_MOD_COL);	/*!< Name of column c
155 155
 str db_url          = str_init(DEFAULT_DB_URL);	/*!< Database URL */
156 156
 int timer_interval  = 60;				/*!< Timer interval in seconds */
157 157
 int db_mode         = 0;				/*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
158
+int db_load         = 1;				/*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */
159
+int db_insert_update = 0;				/*!< Database : update on duplicate key instead of error */
158 160
 int use_domain      = 0;				/*!< Whether usrloc should use domain part of aor */
159 161
 int desc_time_order = 0;				/*!< By default do not enable timestamp ordering */
160 162
 int handle_lost_tcp = 0;				/*!< By default do not remove contacts before expiration time */
... ...
@@ -202,6 +204,8 @@ static param_export_t params[] = {
202 204
 	{"db_url",              PARAM_STR, &db_url        },
203 205
 	{"timer_interval",      INT_PARAM, &timer_interval  },
204 206
 	{"db_mode",             INT_PARAM, &db_mode         },
207
+	{"db_load",             INT_PARAM, &db_load         },
208
+	{"db_insert_update",    INT_PARAM, &db_insert_update },
205 209
 	{"use_domain",          INT_PARAM, &use_domain      },
206 210
 	{"desc_time_order",     INT_PARAM, &desc_time_order },
207 211
 	{"user_agent_column",   PARAM_STR, &user_agent_col},
... ...
@@ -405,6 +409,7 @@ static int child_init(int _rank)
405 409
 			break;
406 410
 		case DB_READONLY:
407 411
 			/* connect to db only from child 1 for preload */
412
+			db_load=1; /* we always load from the db in this mode */
408 413
 			if(_rank!=PROC_SIPINIT)
409 414
 				return 0;
410 415
 			break;
... ...
@@ -416,7 +421,7 @@ static int child_init(int _rank)
416 421
 		return -1;
417 422
 	}
418 423
 	/* _rank==PROC_SIPINIT is used even when fork is disabled */
419
-	if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY) {
424
+	if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY && db_load) {
420 425
 		/* if cache is used, populate domains from DB */
421 426
 		for( ptr=root ; ptr ; ptr=ptr->next) {
422 427
 			if (preload_udomain(ul_dbh, ptr->d) < 0) {
Browse code

usrloc: removed mi commands

Daniel-Constantin Mierla authored on 02/01/2017 19:26:12
Showing 1 changed files
... ...
@@ -53,7 +53,6 @@
53 53
 #include "udomain.h"         /* {insert,delete,get,release}_urecord */
54 54
 #include "urecord.h"         /* {insert,delete,get}_ucontact */
55 55
 #include "ucontact.h"        /* update_ucontact */
56
-#include "ul_mi.h"
57 56
 #include "ul_rpc.h"
58 57
 #include "ul_callback.h"
59 58
 #include "usrloc.h"
... ...
@@ -97,7 +96,6 @@ static void ul_core_timer(unsigned int ticks, void* param);  /*!< Core timer han
97 96
 static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */
98 97
 static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer handler */
99 98
 static int child_init(int rank);                    /*!< Per-child init function */
100
-static int mi_child_init(void);
101 99
 
102 100
 #define UL_PRELOAD_SIZE	8
103 101
 static char* ul_preload_list[UL_PRELOAD_SIZE];
... ...
@@ -188,7 +186,7 @@ static cmd_export_t cmds[] = {
188 186
 
189 187
 
190 188
 /*! \brief
191
- * Exported parameters 
189
+ * Exported parameters
192 190
  */
193 191
 static param_export_t params[] = {
194 192
 	{"ruid_column",         PARAM_STR, &ruid_col      },
... ...
@@ -245,30 +243,13 @@ stat_export_t mod_stats[] = {
245 243
 };
246 244
 
247 245
 
248
-static mi_export_t mi_cmds[] = {
249
-	{ MI_USRLOC_RM,           mi_usrloc_rm_aor,       0,                 0,
250
-				mi_child_init },
251
-	{ MI_USRLOC_RM_CONTACT,   mi_usrloc_rm_contact,   0,                 0,
252
-				mi_child_init },
253
-	{ MI_USRLOC_DUMP,         mi_usrloc_dump,         0,                 0,
254
-				0             },
255
-	{ MI_USRLOC_FLUSH,        mi_usrloc_flush,        MI_NO_INPUT_FLAG,  0,
256
-				mi_child_init },
257
-	{ MI_USRLOC_ADD,          mi_usrloc_add,          0,                 0,
258
-				mi_child_init },
259
-	{ MI_USRLOC_SHOW_CONTACT, mi_usrloc_show_contact, 0,                 0,
260
-				mi_child_init },
261
-	{ 0, 0, 0, 0, 0}
262
-};
263
-
264
-
265 246
 struct module_exports exports = {
266 247
 	"usrloc",
267 248
 	DEFAULT_DLFLAGS, /*!< dlopen flags */
268 249
 	cmds,       /*!< Exported functions */
269 250
 	params,     /*!< Export parameters */
270 251
 	mod_stats,  /*!< exported statistics */
271
-	mi_cmds,    /*!< exported MI functions */
252
+	0,          /*!< exported MI functions */
272 253
 	0,          /*!< exported pseudo-variables */
273 254
 	0,          /*!< extra processes */
274 255
 	mod_init,   /*!< Module initialization function */
... ...
@@ -296,12 +277,6 @@ static int mod_init(void)
296 277
 		return -1;
297 278
 	}
298 279
 #endif
299
-	
300
-	if(register_mi_mod(exports.name, mi_cmds)!=0)
301
-	{
302
-		LM_ERR("failed to register MI commands\n");
303
-		return -1;
304
-	}
305 280
 
306 281
 	if (rpc_register_array(ul_rpc)!=0)
307 282
 	{
... ...
@@ -457,30 +432,6 @@ static int child_init(int _rank)
457 432
 }
458 433
 
459 434
 
460
-/* */
461
-static int mi_child_init(void)
462
-{