api.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include "../../dprint.h"
  26. #include "ht_api.h"
  27. #include "api.h"
  28. #include "ht_dmq.h"
  29. /**
  30. *
  31. */
  32. int ht_api_set_cell(str *hname, str *name, int type,
  33. int_str *val, int mode)
  34. {
  35. ht_t* ht;
  36. ht = ht_get_table(hname);
  37. if(ht==NULL)
  38. return -1;
  39. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, hname, name, type, val, mode)!=0) {
  40. LM_ERR("dmq relication failed\n");
  41. }
  42. return ht_set_cell(ht, name, type, val, mode);
  43. }
  44. /**
  45. *
  46. */
  47. int ht_api_del_cell(str *hname, str *name)
  48. {
  49. ht_t* ht;
  50. ht = ht_get_table(hname);
  51. if(ht==NULL)
  52. return -1;
  53. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, hname, name, 0, NULL, 0)!=0) {
  54. LM_ERR("dmq relication failed\n");
  55. }
  56. return ht_del_cell(ht, name);
  57. }
  58. /**
  59. *
  60. */
  61. int ht_api_set_cell_expire(str *hname, str *name,
  62. int type, int_str *val)
  63. {
  64. ht_t* ht;
  65. ht = ht_get_table(hname);
  66. if(ht==NULL)
  67. return -1;
  68. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, hname, name, type, val, 0)!=0) {
  69. LM_ERR("dmq relication failed\n");
  70. }
  71. return ht_set_cell_expire(ht, name, type, val);
  72. }
  73. /**
  74. *
  75. */
  76. int ht_api_get_cell_expire(str *hname, str *name,
  77. unsigned int *val)
  78. {
  79. ht_t* ht;
  80. ht = ht_get_table(hname);
  81. if(ht==NULL)
  82. return -1;
  83. return ht_get_cell_expire(ht, name, val);
  84. }
  85. /**
  86. *
  87. */
  88. int ht_api_rm_cell_re(str *hname, str *sre, int mode)
  89. {
  90. ht_t* ht;
  91. int_str isval;
  92. ht = ht_get_table(hname);
  93. if(ht==NULL)
  94. return -1;
  95. if (ht->dmqreplicate>0) {
  96. isval.s.s = sre->s;
  97. isval.s.len = sre->len;
  98. if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, hname, NULL, AVP_VAL_STR, &isval, mode)!=0) {
  99. LM_ERR("dmq relication failed\n");
  100. }
  101. }
  102. if(ht_rm_cell_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
  103. return -1;
  104. return 0;
  105. }
  106. /**
  107. *
  108. */
  109. int ht_api_count_cells_re(str *hname, str *sre, int mode)
  110. {
  111. ht_t* ht;
  112. ht = ht_get_table(hname);
  113. if(ht==NULL)
  114. return -1;
  115. if(ht_count_cells_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
  116. return -1;
  117. return 0;
  118. }
  119. /**
  120. *
  121. */
  122. int bind_htable(htable_api_t* api)
  123. {
  124. if (!api) {
  125. ERR("Invalid parameter value\n");
  126. return -1;
  127. }
  128. api->set = ht_api_set_cell;
  129. api->rm = ht_api_del_cell;
  130. api->set_expire = ht_api_set_cell_expire;
  131. api->get_expire = ht_api_get_cell_expire;
  132. api->rm_re = ht_api_rm_cell_re;
  133. api->count_re = ht_api_count_cells_re;
  134. return 0;
  135. }