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

Function mi_reload

modules/sql_cacher/sql_cacher.c:1207–1301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1205}
1206
1207static mi_item_t *mi_reload(const mi_params_t *params, str *key)
1208{
1209 db_handlers_t *db_hdls;
1210 db_val_t *values;
1211 db_res_t *sql_res = NULL;
1212 struct queried_key *it = NULL;
1213 str entry_id, src_key;
1214 int rld_vers, rc;
1215
1216 if (get_mi_string_param(params, "id", &entry_id.s, &entry_id.len) < 0)
1217 return init_mi_param_error();
1218
1219 for (db_hdls = db_hdls_list; db_hdls; db_hdls = db_hdls->next)
1220 if (!str_strcmp(&db_hdls->c_entry->id, &entry_id))
1221 break;
1222 if (!db_hdls) {
1223 LM_ERR("Entry %.*s not found\n", entry_id.len, entry_id.s);
1224 return init_mi_error(500, MI_SSTR("ERROR Cache entry not found"));
1225 }
1226
1227 if (db_hdls->c_entry->on_demand || key) {
1228 if (key) {
1229 if (db_hdls->c_entry->on_demand) {
1230 src_key.len = db_hdls->c_entry->id.len + key->len;
1231 src_key.s = pkg_malloc(src_key.len);
1232 if (!src_key.s) {
1233 LM_ERR("No more pkg memory\n");
1234 return NULL;
1235 }
1236 memcpy(src_key.s, db_hdls->c_entry->id.s, db_hdls->c_entry->id.len);
1237 memcpy(src_key.s + db_hdls->c_entry->id.len, key->s, key->len);
1238
1239 lock_get(queries_lock);
1240
1241 for (it = *queries_in_progress; it; it = it->next)
1242 if (!str_strcmp(&it->key, &src_key))
1243 break;
1244 pkg_free(src_key.s);
1245 if (it) { /* key is in list */
1246 lock_release(queries_lock);
1247 lock_get(it->wait_sql_query);
1248 }
1249 } else {
1250 lock_start_write(db_hdls->c_entry->ref_lock);
1251 }
1252
1253 if ((rld_vers = get_rld_vers_from_cache(db_hdls->c_entry, db_hdls)) < 0) {
1254 LM_ERR("Unable to fetch reload version counter\n");
1255 if (db_hdls->c_entry->on_demand) {
1256 if (it)
1257 lock_release(it->wait_sql_query);
1258 else
1259 lock_release(queries_lock);
1260 } else {
1261 lock_stop_write(db_hdls->c_entry->ref_lock);
1262 }
1263
1264 return init_mi_error(500, MI_SSTR("ERROR Reloading key from SQL"

Callers 2

mi_reload_1Function · 0.70
mi_reload_2Function · 0.70

Calls 9

get_mi_string_paramFunction · 0.85
init_mi_param_errorFunction · 0.85
init_mi_errorFunction · 0.85
lock_getFunction · 0.85
lock_releaseFunction · 0.85
get_rld_vers_from_cacheFunction · 0.85
load_keyFunction · 0.85
inc_cache_rld_versFunction · 0.85
load_entire_tableFunction · 0.85

Tested by

no test coverage detected