1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/**
* $Id$
*
* Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com)
*
* This file is part of kamailio, a free SIP server.
*
* Kamailio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* Kamailio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! \file
* \ingroup sqlops
* \brief SIP-router SQL-operations :: API
*
* - Module: \ref sqlops
*/
#ifndef _SQL_API_H_
#define _SQL_API_H_
#include "../../sr_module.h"
#include "../../lib/srdb1/db.h"
#include "../../pvar.h"
typedef struct _sql_col
{
str name;
unsigned int colid;
} sql_col_t;
typedef struct _sql_val
{
int flags;
int_str value;
} sql_val_t;
typedef struct _sql_result
{
unsigned int resid;
str name;
int nrows;
int ncols;
sql_col_t *cols;
sql_val_t **vals;
struct _sql_result *next;
} sql_result_t;
typedef struct _sql_con
{
str name;
unsigned int conid;
str db_url;
db1_con_t *dbh;
db_func_t dbf;
struct _sql_con *next;
} sql_con_t;
int sql_parse_param(char *val);
void sql_destroy(void);
int sql_connect(void);
int sql_do_query(sql_con_t *con, str *query, sql_result_t *res);
int sql_do_query_async(sql_con_t *con, str *query);
#ifdef WITH_XAVP
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(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
pvname_list_t *res);
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);
sql_con_t* sql_get_connection(str *name);
sql_result_t* sql_get_result(str *name);
void sql_reset_result(sql_result_t *res);
typedef int (*sqlops_do_query_f)(str *scon, str *squery, str *sres);
int sqlops_do_query(str *scon, str *squery, str *sres);
typedef int (*sqlops_get_value_f)(str *sres, int i, int j, sql_val_t **val);
int sqlops_get_value(str *sres, int i, int j, sql_val_t **val);
typedef int (*sqlops_is_null_f)(str *sres, int i, int j);
int sqlops_is_null(str *res, int i, int j);
typedef int (*sqlops_get_column_f)(str *sres, int i, str *col);
int sqlops_get_column(str *sres, int i, str *name);
typedef int (*sqlops_num_columns_f)(str *sres);
int sqlops_num_columns(str *sres);
typedef int (*sqlops_num_rows_f)(str *sres);
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;
sqlops_is_null_f is_null;
sqlops_get_column_f column;
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);
/**
* @brief Load the SQLOps API
*/
static inline int sqlops_load_api(sqlops_api_t *sqb)
{
bind_sqlops_f bindsqlops;
bindsqlops = (bind_sqlops_f)find_export("bind_sqlops", 0, 0);
if ( bindsqlops == 0) {
LM_ERR("cannot find bind_sqlops\n");
return -1;
}
if (bindsqlops(sqb)==-1)
{
LM_ERR("cannot bind sqlops api\n");
return -1;
}
return 0;
}
#endif
|