Module: sip-router Branch: master Commit: 7fceaf17a4d3e7bef9767e8e5cbcfaa3f85e0406 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7fceaf17...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Sat Feb 25 11:25:52 2012 +0100
sqlops: exported sql_xquery() via inter-module API
- sql_do_xquery() split to add a function that takes str parameters
---
modules_k/sqlops/sql_api.c | 69 +++++++++++++++++++++++++++++++++----------- modules_k/sqlops/sql_api.h | 10 ++++-- modules_k/sqlops/sqlops.c | 16 ++++------ 3 files changed, 65 insertions(+), 30 deletions(-)
diff --git a/modules_k/sqlops/sql_api.c b/modules_k/sqlops/sql_api.c index cdf6452..c02ac81 100644 --- a/modules_k/sqlops/sql_api.c +++ b/modules_k/sqlops/sql_api.c @@ -408,33 +408,22 @@ error: }
#ifdef WITH_XAVP -int sql_do_xquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query, - pv_elem_t *res) +int sql_exec_xquery(struct sip_msg *msg, sql_con_t *con, str *query, + str *xavp) { db1_res_t* db_res = NULL; sr_xavp_t *row = NULL; sr_xval_t val; int i, j; - str sv, xavp; + str sv;
- if(msg==NULL || query==NULL || res==NULL) + if(msg==NULL || query==NULL || xavp==NULL) { LM_ERR("bad parameters\n"); return -1; } - if(pv_printf_s(msg, query, &sv)!=0) - { - LM_ERR("cannot print the sql query\n"); - return -1; - } - - if(pv_printf_s(msg, res, &xavp)!=0) - { - LM_ERR("cannot print the result parameter\n"); - return -1; - }
- if(con->dbf.raw_query(con->dbh, &sv, &db_res)!=0) + if(con->dbf.raw_query(con->dbh, query, &db_res)!=0) { LM_ERR("cannot do the query\n"); return -1; @@ -529,7 +518,7 @@ int sql_do_xquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query, val.type = SR_XTYPE_XAVP; val.v.xavp = row; LM_DBG("Adding row\n"); - xavp_add_value(&xavp, &val, NULL); + xavp_add_value(xavp, &val, NULL); }
con->dbf.free_result(con->dbh, db_res); @@ -540,6 +529,30 @@ error: return -1;
} + +int sql_do_xquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query, + pv_elem_t *res) +{ + str sv, xavp; + if(msg==NULL || query==NULL || res==NULL) + { + LM_ERR("bad parameters\n"); + return -1; + } + if(pv_printf_s(msg, query, &sv)!=0) + { + LM_ERR("cannot print the sql query\n"); + return -1; + } + + if(pv_printf_s(msg, res, &xavp)!=0) + { + LM_ERR("cannot print the result parameter\n"); + return -1; + } + return sql_exec_xquery(msg, con, &sv, &xavp); +} + #endif
@@ -831,3 +844,25 @@ void sqlops_reset_result(str *sres)
return; } + +/** + * + */ +int sqlops_do_xquery(sip_msg_t *msg, str *scon, str *squery, str *xavp) +{ + sql_con_t *con = NULL; + + con = sql_get_connection(scon); + if(con==NULL) + { + LM_ERR("invalid connection [%.*s]\n", scon->len, scon->s); + goto error; + } + if(sql_exec_xquery(msg, con, squery, xavp)<0) + goto error; + + return 0; +error: + return -1; +} + diff --git a/modules_k/sqlops/sql_api.h b/modules_k/sqlops/sql_api.h index 94c30a2..504a1ab 100644 --- a/modules_k/sqlops/sql_api.h +++ b/modules_k/sqlops/sql_api.h @@ -74,12 +74,12 @@ int sql_connect(void);
int sql_do_query(sql_con_t *con, str *query, sql_result_t *res); #ifdef WITH_XAVP -int sql_do_xquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query, +int sql_do_xquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query, pv_elem_t *res); #endif -int sql_do_pvquery(struct sip_msg *msg, sql_con_t *con, pv_elem_t *query, +int sql_do_pvquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query, pvname_list_t *res); -int pv_get_sqlrows(struct sip_msg *msg, pv_param_t *param, +int pv_get_sqlrows(sip_msg_t *msg, pv_param_t *param, pv_value_t *res); int pv_parse_con_name(pv_spec_p sp, str *in);
@@ -109,6 +109,9 @@ int sqlops_num_rows(str *sres); typedef void (*sqlops_reset_result_f)(str *sres); void sqlops_reset_result(str *sres);
+typedef int (*sqlops_do_xquery_f)(sip_msg_t *msg, str *scon, str *squery, str *sxavp); +int sqlops_do_xquery(sip_msg_t *msg, str *scon, str *squery, str *sxavp); + typedef struct sqlops_api { sqlops_do_query_f query; sqlops_get_value_f value; @@ -117,6 +120,7 @@ typedef struct sqlops_api { sqlops_reset_result_f reset; sqlops_num_rows_f nrows; sqlops_num_columns_f ncols; + sqlops_do_xquery_f xquery; } sqlops_api_t;
typedef int (*bind_sqlops_f)(sqlops_api_t* api); diff --git a/modules_k/sqlops/sqlops.c b/modules_k/sqlops/sqlops.c index 3029747..695c6c5 100644 --- a/modules_k/sqlops/sqlops.c +++ b/modules_k/sqlops/sqlops.c @@ -90,22 +90,17 @@ static pv_export_t mod_pvs[] = {
static cmd_export_t cmds[]={ {"sql_query", (cmd_function)sql_query, 3, fixup_sql_query, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + ANY_ROUTE}, {"sql_query", (cmd_function)sql_query2, 2, fixup_sql_query, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + ANY_ROUTE}, #ifdef WITH_XAVP {"sql_xquery", (cmd_function)sql_xquery, 3, fixup_sql_xquery, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + ANY_ROUTE}, #endif {"sql_pvquery", (cmd_function)sql_pvquery, 3, fixup_sql_pvquery, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + ANY_ROUTE}, {"sql_result_free", (cmd_function)sql_rfree, 1, fixup_sql_rfree, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + ANY_ROUTE}, {"bind_sqlops", (cmd_function)bind_sqlops, 0, 0, 0, 0}, {0,0,0,0,0,0} }; @@ -426,6 +421,7 @@ static int bind_sqlops(sqlops_api_t* api) api->reset = sqlops_reset_result; api->nrows = sqlops_num_rows; api->ncols = sqlops_num_columns; + api->xquery = sqlops_do_xquery;
return 0; }