[sr-dev] git:master:3b2a0a84: sqlops: export sql_pvquery to KEMI

Victor Seva linuxmaniac at torreviejawireless.org
Fri Jun 12 09:32:19 CEST 2020


Module: kamailio
Branch: master
Commit: 3b2a0a849e60a6bf0bc9d8054568c954010d7aa6
URL: https://github.com/kamailio/kamailio/commit/3b2a0a849e60a6bf0bc9d8054568c954010d7aa6

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2020-06-12T09:32:09+02:00

sqlops: export sql_pvquery to KEMI

---

Modified: src/modules/sqlops/sqlops.c

---

Diff:  https://github.com/kamailio/kamailio/commit/3b2a0a849e60a6bf0bc9d8054568c954010d7aa6.diff
Patch: https://github.com/kamailio/kamailio/commit/3b2a0a849e60a6bf0bc9d8054568c954010d7aa6.patch

---

diff --git a/src/modules/sqlops/sqlops.c b/src/modules/sqlops/sqlops.c
index b3f21f6ff3..5eec552b65 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,




More information about the sr-dev mailing list