bdb_mod.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * $Id$
  3. *
  4. * db_berkeley module, portions of this code were templated using
  5. * the dbtext and postgres modules.
  6. * Copyright (C) 2007 Cisco Systems
  7. *
  8. * This file is part of SIP-router, a free SIP server.
  9. *
  10. * SIP-router is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * SIP-router is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * History:
  25. * --------
  26. * 2007-09-19 genesis (wiquan)
  27. */
  28. /*! \file
  29. * Berkeley DB : Module interface
  30. *
  31. * \ingroup database
  32. */
  33. #include <stdio.h>
  34. #include <unistd.h>
  35. #include <sys/stat.h>
  36. #include "../../str.h"
  37. #include "../../ut.h"
  38. #include "../../mem/mem.h"
  39. #include "../../sr_module.h"
  40. #include "../../lib/srdb2/db_res.h"
  41. #include "../../lib/srdb2/db.h"
  42. #include "bdb_lib.h"
  43. #include "bdb_con.h"
  44. #include "bdb_uri.h"
  45. #include "bdb_fld.h"
  46. #include "bdb_res.h"
  47. #include "bdb_cmd.h"
  48. #include "km_db_berkeley.h"
  49. MODULE_VERSION
  50. int auto_reload = 0;
  51. int log_enable = 0;
  52. int journal_roll_interval = 0;
  53. static int bdb_mod_init(void);
  54. static void bdb_mod_destroy(void);
  55. /*
  56. * Exported functions
  57. */
  58. static cmd_export_t cmds[] = {
  59. {"db_ctx", (cmd_function)NULL, 0, 0, 0},
  60. {"db_con", (cmd_function)bdb_con, 0, 0, 0},
  61. {"db_uri", (cmd_function)bdb_uri, 0, 0, 0},
  62. {"db_cmd", (cmd_function)bdb_cmd, 0, 0, 0},
  63. {"db_put", (cmd_function)bdb_cmd_exec, 0, 0, 0},
  64. {"db_del", (cmd_function)bdb_cmd_exec, 0, 0, 0},
  65. {"db_get", (cmd_function)bdb_cmd_exec, 0, 0, 0},
  66. {"db_upd", (cmd_function)bdb_cmd_exec, 0, 0, 0},
  67. {"db_sql", (cmd_function)bdb_cmd_exec, 0, 0, 0},
  68. {"db_first", (cmd_function)bdb_cmd_first, 0, 0, 0},
  69. {"db_next", (cmd_function)bdb_cmd_next, 0, 0, 0},
  70. {"db_res", (cmd_function)bdb_res, 0, 0, 0},
  71. {"db_fld", (cmd_function)bdb_fld, 0, 0, 0},
  72. {"db_bind_api", (cmd_function)bdb_bind_api, 0, 0, 0},
  73. {0, 0, 0, 0, 0}
  74. };
  75. /*
  76. * Exported parameters
  77. */
  78. static param_export_t params[] = {
  79. {"auto_reload", INT_PARAM, &auto_reload },
  80. {"log_enable", INT_PARAM, &log_enable },
  81. {"journal_roll_interval", INT_PARAM, &journal_roll_interval },
  82. {0, 0, 0}
  83. };
  84. struct module_exports exports = {
  85. "db_berkeley",
  86. cmds, /* Exported functions */
  87. 0, /* RPC method */
  88. params, /* Exported parameters */
  89. bdb_mod_init, /* module initialization function */
  90. 0, /* response function*/
  91. bdb_mod_destroy, /* destroy function */
  92. 0, /* oncancel function */
  93. 0 /* per-child init function */
  94. };
  95. int mod_register(char *path, int *dlflags, void *p1, void *p2)
  96. {
  97. if(db_api_init()<0)
  98. return -1;
  99. return 0;
  100. }
  101. static int bdb_mod_init(void)
  102. {
  103. bdb_params_t p;
  104. p.auto_reload = auto_reload;
  105. p.log_enable = log_enable;
  106. p.cache_size = (4 * 1024 * 1024); //4Mb
  107. p.journal_roll_interval = journal_roll_interval;
  108. if(bdblib_init(&p))
  109. return -1;
  110. return km_mod_init();
  111. }
  112. static void bdb_mod_destroy(void)
  113. {
  114. km_destroy();
  115. bdblib_destroy();
  116. }