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

Function pv_get_sql_cached_value

modules/sql_cacher/sql_cacher.c:1937–2102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1935
1936static str valbuff[PV_VAL_BUF_NO];
1937int pv_get_sql_cached_value(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
1938{
1939 pv_name_fix_t *pv_name;
1940 str name_s;
1941 db_handlers_t *it_db;
1942 int rc, rc2, int_res = 0, l = 0;
1943 char *ch = NULL;
1944 str str_res = {NULL, 0}, cdb_res = {NULL, 0};
1945 static int buf_itr = 0;
1946 int entry_rld_vers, free_str_res = 0;
1947
1948 if (!param || param->pvn.type != PV_NAME_PVAR ||
1949 !param->pvn.u.dname) {
1950 LM_CRIT("Bad pvar get function parameters\n");
1951 return -1;
1952 }
1953
1954 pv_name = (pv_name_fix_t *)param->pvn.u.dname;
1955 if (!pv_name) {
1956 LM_ERR("Unable to get name struct from dname\n");
1957 return -1;
1958 }
1959
1960 if (pv_name->pv_elem_list) {
1961 /* there are variables in the name which need to be evaluated, then parse */
1962 if (pv_printf_s(msg, pv_name->pv_elem_list, &name_s) != 0 ||
1963 name_s.len == 0 || !name_s.s) {
1964 LM_ERR("Unable to evaluate variables in pv name\n");
1965 return pv_get_null(msg, param, res);
1966 }
1967 if (parse_pv_name_s(pv_name, &name_s) < 0)
1968 return pv_get_null(msg, param, res);
1969 }
1970
1971 if (!pv_name->c_entry) {
1972 for (it_db = db_hdls_list; it_db; it_db = it_db->next)
1973 if (!str_strcmp(&it_db->c_entry->id, &pv_name->id)) {
1974 pv_name->c_entry = it_db->c_entry;
1975 pv_name->db_hdls = it_db;
1976 break;
1977 }
1978 if (!it_db) {
1979 LM_WARN("Unknown caching id %.*s\n", pv_name->id.len, pv_name->id.s);
1980 return pv_get_null(msg, param, res);
1981 }
1982 }
1983
1984 if (!pv_name->c_entry->on_demand)
1985 lock_start_read(pv_name->c_entry->ref_lock);
1986
1987 rc = cdb_fetch(pv_name, &cdb_res, &entry_rld_vers);
1988 if (rc == -1) {
1989 LM_ERR("Error fetching from cachedb\n");
1990 if (!pv_name->c_entry->on_demand)
1991 lock_stop_read(pv_name->c_entry->ref_lock);
1992 return pv_get_null(msg, param, res);
1993 }
1994

Callers

nothing calls this directly

Calls 9

pv_printf_sFunction · 0.85
pv_get_nullFunction · 0.85
parse_pv_name_sFunction · 0.85
cdb_fetchFunction · 0.85
optimize_cdb_decodeFunction · 0.85
cdb_val_decodeFunction · 0.85
on_demand_loadFunction · 0.85
pkg_str_extendFunction · 0.85
int2strFunction · 0.85

Tested by

no test coverage detected