From 3b2a0a849e60a6bf0bc9d8054568c954010d7aa6 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 9 Jun 2020 12:02:43 +0200 Subject: [PATCH] sqlops: export sql_pvquery to KEMI --- src/modules/sqlops/sqlops.c | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/modules/sqlops/sqlops.c b/src/modules/sqlops/sqlops.c index b3f21f6ff34..5eec552b650 100644 --- a/src/modules/sqlops/sqlops.c +++ b/src/modules/sqlops/sqlops.c @@ -492,6 +492,60 @@ static int ki_sqlops_query(sip_msg_t *msg, str *scon, str *squery, str *sres) return sqlops_do_query(scon, squery, sres); } +static int ki_sqlops_pvquery(sip_msg_t *msg, str *scon, str *squery, str *sres) +{ + pv_elem_t *query = NULL; + pvname_list_t *pv_res = NULL; + pvname_list_t *pvl = NULL; + sql_con_t *con = NULL; + int i, res; + + if (scon == NULL || scon->s == NULL || scon->len<=0) { + LM_ERR("invalid connection name\n"); + return -1; + } + + con = sql_get_connection(scon); + if(con==NULL) { + LM_ERR("invalid connection [%.*s]\n", scon->len, scon->s); + return -1; + } + + if(pv_parse_format(squery, &query)<0) + { + LM_ERR("invalid query string [%s]\n", squery->s); + return -1; + } + + /* parse result variables into list of pv_spec_t's */ + pv_res = parse_pvname_list(sres, 0); + if(pv_res==NULL) + { + LM_ERR("invalid result parameter [%s]\n", sres->s); + pv_elem_free_all(query); + return -1; + } + /* check if all result variables are writable */ + pvl = pv_res; + i = 1; + while (pvl) { + if (pvl->sname.setf == NULL) + { + LM_ERR("result variable [%d] is read-only\n", i); + pv_elem_free_all(query); + free_pvname_list(pv_res); + return -1; + } + i++; + pvl = pvl->next; + } + res = sql_do_pvquery(msg, con, query, pv_res); + + pv_elem_free_all(query); + free_pvname_list(pv_res); + return res; +} + static int ki_sqlops_query_async(sip_msg_t *msg, str *scon, str *squery) { sql_con_t *con = NULL; @@ -642,6 +696,11 @@ static sr_kemi_t sr_kemi_sqlops_exports[] = { { SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("sqlops"), str_init("sql_pvquery"), + SR_KEMIP_INT, ki_sqlops_pvquery, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { str_init("sqlops"), str_init("sql_xquery"), SR_KEMIP_INT, sqlops_do_xquery, { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,