api.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. *
  3. * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com)
  4. *
  5. * This file is part of kamailio, a free SIP server.
  6. *
  7. * Kamailio 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. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include "../../dprint.h"
  25. #include "ht_api.h"
  26. #include "api.h"
  27. #include "ht_dmq.h"
  28. /**
  29. *
  30. */
  31. int ht_api_set_cell(str *hname, str *name, int type,
  32. int_str *val, int mode)
  33. {
  34. ht_t* ht;
  35. ht = ht_get_table(hname);
  36. if(ht==NULL)
  37. return -1;
  38. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL, hname, name, type, val, mode)!=0) {
  39. LM_ERR("dmq relication failed\n");
  40. }
  41. return ht_set_cell(ht, name, type, val, mode);
  42. }
  43. /**
  44. *
  45. */
  46. int ht_api_del_cell(str *hname, str *name)
  47. {
  48. ht_t* ht;
  49. ht = ht_get_table(hname);
  50. if(ht==NULL)
  51. return -1;
  52. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_DEL_CELL, hname, name, 0, NULL, 0)!=0) {
  53. LM_ERR("dmq relication failed\n");
  54. }
  55. return ht_del_cell(ht, name);
  56. }
  57. /**
  58. *
  59. */
  60. int ht_api_set_cell_expire(str *hname, str *name,
  61. int type, int_str *val)
  62. {
  63. ht_t* ht;
  64. ht = ht_get_table(hname);
  65. if(ht==NULL)
  66. return -1;
  67. if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, hname, name, type, val, 0)!=0) {
  68. LM_ERR("dmq relication failed\n");
  69. }
  70. return ht_set_cell_expire(ht, name, type, val);
  71. }
  72. /**
  73. *
  74. */
  75. int ht_api_get_cell_expire(str *hname, str *name,
  76. unsigned int *val)
  77. {
  78. ht_t* ht;
  79. ht = ht_get_table(hname);
  80. if(ht==NULL)
  81. return -1;
  82. return ht_get_cell_expire(ht, name, val);
  83. }
  84. /**
  85. *
  86. */
  87. int ht_api_rm_cell_re(str *hname, str *sre, int mode)
  88. {
  89. ht_t* ht;
  90. int_str isval;
  91. ht = ht_get_table(hname);
  92. if(ht==NULL)
  93. return -1;
  94. if (ht->dmqreplicate>0) {
  95. isval.s.s = sre->s;
  96. isval.s.len = sre->len;
  97. if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, hname, NULL, AVP_VAL_STR, &isval, mode)!=0) {
  98. LM_ERR("dmq relication failed\n");
  99. }
  100. }
  101. if(ht_rm_cell_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
  102. return -1;
  103. return 0;
  104. }
  105. /**
  106. *
  107. */
  108. int ht_api_count_cells_re(str *hname, str *sre, int mode)
  109. {
  110. ht_t* ht;
  111. ht = ht_get_table(hname);
  112. if(ht==NULL)
  113. return -1;
  114. if(ht_count_cells_re(sre, ht, mode /* 0 - name; 1 - value */)<0)
  115. return -1;
  116. return 0;
  117. }
  118. /**
  119. *
  120. */
  121. int bind_htable(htable_api_t* api)
  122. {
  123. if (!api) {
  124. ERR("Invalid parameter value\n");
  125. return -1;
  126. }
  127. api->set = ht_api_set_cell;
  128. api->rm = ht_api_del_cell;
  129. api->set_expire = ht_api_set_cell_expire;
  130. api->get_expire = ht_api_get_cell_expire;
  131. api->rm_re = ht_api_rm_cell_re;
  132. api->count_re = ht_api_count_cells_re;
  133. return 0;
  134. }