MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / dp_load_db

Function dp_load_db

modules/dialplan/dp_db.c:246–444  ·  view source on GitHub ↗

load rules from DB*/

Source from the content-addressed store, hash-verified

244
245/*load rules from DB*/
246int dp_load_db(dp_connection_list_p dp_conn, int initial)
247{
248 int i, nr_rows;
249 db_res_t * res = 0;
250 db_val_t * values;
251 db_row_t * rows;
252 db_key_t query_cols[DP_TABLE_COL_NO] = {
253 &dpid_column, &pr_column,
254 &match_op_column, &match_exp_column, &match_flags_column,
255 &subst_exp_column, &repl_exp_column, &attrs_column, &timerec_column };
256 db_key_t order = &pr_column;
257 /* disabled condition */
258 db_key_t cond_cols[1] = { &disabled_column };
259 db_val_t cond_val[1];
260
261 dpl_node_t *rule;
262 int no_rows = 10;
263 int loaded_rl=0, discarded_rl=0;
264
265
266 lock_start_write( dp_conn->ref_lock );
267
268 if( dp_conn->crt_index != dp_conn->next_index){
269 LM_WARN("a load command already in-progress for partition <%.*s>, "
270 "aborting reload...\n", dp_conn->partition.len, dp_conn->partition.s);
271 lock_stop_write( dp_conn->ref_lock );
272 return 0;
273 }
274
275 dp_conn->next_index = dp_conn->crt_index == 0 ? 1 : 0;
276
277 lock_stop_write( dp_conn->ref_lock );
278
279 sr_add_report( dp_srg, STR2CI(dp_conn->partition),
280 CHAR_INT("starting DB data loading"), 0);
281 if (initial)
282 sr_set_status( dp_srg, STR2CI(dp_conn->partition),
283 SR_STATUS_LOADING_DATA, CHAR_INT("startup data loading"), 0);
284 else
285 sr_set_status( dp_srg, STR2CI(dp_conn->partition),
286 SR_STATUS_RELOADING_DATA, CHAR_INT("data re-loading"), 0);
287
288 if (dp_conn->dp_dbf.use_table(*dp_conn->dp_db_handle, &dp_conn->table_name) < 0){
289 LM_ERR("error in use_table\n");
290 goto err1;
291 }
292
293 VAL_TYPE(cond_val) = DB_INT;
294 VAL_NULL(cond_val) = 0;
295 VAL_INT(cond_val) = 0;
296
297 if (DB_CAPABILITY(dp_conn->dp_dbf, DB_CAP_FETCH)) {
298 if(dp_conn->dp_dbf.query(*dp_conn->dp_db_handle,cond_cols,
299 0,cond_val,query_cols,1,
300 DP_TABLE_COL_NO, order, 0) < 0){
301 LM_ERR("failed to query database!\n");
302
303 goto err1;

Callers 2

dp_load_all_dbFunction · 0.85
mi_reload_rules_1Function · 0.85

Calls 9

sr_add_reportFunction · 0.85
sr_set_statusFunction · 0.85
estimate_available_rowsFunction · 0.85
build_ruleFunction · 0.85
add_rule2hashFunction · 0.85
destroy_hashFunction · 0.85
list_hashFunction · 0.85
sr_add_report_fmtFunction · 0.85
destroy_ruleFunction · 0.85

Tested by

no test coverage detected