sql_api.h 3.7 KB

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