Module: kamailio
Branch: 5.3
Commit: 12386b2f4cc33f3ee0ea366ddcf48b124d2265aa
URL: 
https://github.com/kamailio/kamailio/commit/12386b2f4cc33f3ee0ea366ddcf48b124d2265aa

Author: Victor Seva <[email protected]>
Committer: Victor Seva <[email protected]>
Date: 2020-06-22T10:24:23+02:00

sqlops: export sql_pvquery to KEMI

(cherry picked from commit 3b2a0a849e60a6bf0bc9d8054568c954010d7aa6)

---

Modified: src/modules/sqlops/sqlops.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/12386b2f4cc33f3ee0ea366ddcf48b124d2265aa.diff
Patch: 
https://github.com/kamailio/kamailio/commit/12386b2f4cc33f3ee0ea366ddcf48b124d2265aa.patch

---

diff --git a/src/modules/sqlops/sqlops.c b/src/modules/sqlops/sqlops.c
index 3943b1b81a..872755164e 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;
@@ -561,6 +615,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,


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to