bdb_rval.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* $Id$
  2. *
  3. * Copyright (C) 2006-2007 Sippy Software, Inc. <[email protected]>
  4. *
  5. * This file is part of ser, a free SIP server.
  6. *
  7. * ser is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * For a license to use the ser software under conditions
  13. * other than those described here, or to purchase support for this
  14. * software, please contact iptel.org by e-mail at the following addresses:
  15. * [email protected]
  16. *
  17. * ser is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. *
  26. */
  27. #include "bdb.h"
  28. int bdb_rrow_db2bdb(db_con_t* _h, db_key_t* _k, int _n, bdb_rrow_p *_r)
  29. {
  30. bdb_rrow_p r;
  31. bdb_table_p t;
  32. bdb_column_p c;
  33. int found;
  34. int i;
  35. int c_idx;
  36. *_r = NULL;
  37. if ((t = bdb_find_table(CON_TABLE(_h))) == NULL) {
  38. #ifdef BDB_EXTRA_DEBUG
  39. LOG(L_ERR, "BDB:bdb_rrow_db2bdb: no table in use\n");
  40. #endif
  41. return -1;
  42. };
  43. i = (_n == 0) ? BDB_CON_COL_NUM(_h) : _n;
  44. r = pkg_malloc(sizeof(*r) * i);
  45. memset(r, 0, sizeof(*r) * i);
  46. if (_n > 0) {
  47. for (i = 0; i < _n; i++) {
  48. found = 0;
  49. for (c = t->cols, c_idx = 0; c != NULL; c = c->next, c_idx++) {
  50. if (!strcmp(_k[i], c->name.s)) {
  51. #ifdef BDB_EXTRA_DEBUG
  52. LOG(L_NOTICE, "BDB:bdb_rrow_db2bdb: filling column '%.*s', c_idx = %0d\n", c->name.len, c->name.s, c_idx);
  53. #endif
  54. r[i] = c_idx;
  55. found = 1;
  56. break;
  57. }
  58. }
  59. if (!found) {
  60. LOG(L_ERR, "BDB:bdb_rrow_db2bdb: column '%s' does not exist\n", _k[i]);
  61. bdb_free_rrow(r);
  62. return -1;
  63. }
  64. }
  65. } else { /* return all columns */
  66. for (c = t->cols, c_idx = 0; c != NULL; c = c->next, c_idx++) {
  67. #ifdef BDB_EXTRA_DEBUG
  68. LOG(L_NOTICE, "BDB:bdb_rrow_db2bdb: filling column '%.*s', c_idx = %0d\n", c->name.len, c->name.s, c_idx);
  69. #endif
  70. r[c_idx] = c_idx;
  71. }
  72. }
  73. *_r = r;
  74. return 0;
  75. };
  76. void bdb_free_rrow(bdb_rrow_p _r)
  77. {
  78. pkg_free(_r);
  79. };