api.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2008 Telecats BV
  2. *
  3. * This file is part of Kamailio, a free SIP server.
  4. *
  5. * Kamailio is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * Kamailio is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. *
  20. * History:
  21. * ---------
  22. * 2008-07-14 first version (Ardjan Zwartjes)
  23. */
  24. #include "api.h"
  25. #include "textops.h"
  26. #include "../../mod_fix.h"
  27. #include "../../mem/mem.h"
  28. /*
  29. * User friendly wrapper around add_hf_helper, to be called from
  30. * other modules.
  31. */
  32. int append_hf_api(struct sip_msg *msg, str* str_hf){
  33. return add_hf_helper(msg, str_hf, NULL, NULL, 0, NULL);
  34. }
  35. /*
  36. * User friendly wrapper around remove_hf_f, to be called from
  37. * other modules.
  38. */
  39. int remove_hf_api(struct sip_msg *msg, str* str_hf){
  40. return remove_hf_f(msg, (char*)str_hf,NULL);
  41. }
  42. /*
  43. * User friendly wrapper to call search_append from other
  44. * modules
  45. */
  46. int search_append_api(struct sip_msg *msg, str *regex, str *data_str){
  47. int retval;
  48. char *data;
  49. void **param;
  50. data=pkg_malloc(data_str->len+1);
  51. memcpy(data,data_str->s,data_str->len);
  52. memset(data+data_str->len,0,1);
  53. param=pkg_malloc(sizeof(void*));
  54. *param=pkg_malloc(regex->len+1);
  55. memcpy(*param,regex->s,regex->len);
  56. memset(*param+regex->len,0,1);
  57. fixup_regexp_none(param,1);
  58. retval=search_append_f(msg, *param, data);
  59. fixup_free_regexp_none(param,1);
  60. pkg_free(param);
  61. pkg_free(data);
  62. return retval;
  63. }
  64. /*
  65. * User friendly wrapper to call search from other modules.
  66. */
  67. int search_api(struct sip_msg *msg, str *regex){
  68. int retval;
  69. void **param=pkg_malloc(sizeof(void*));
  70. *param=pkg_malloc(regex->len+1);
  71. memcpy(*param,regex->s,regex->len);
  72. memset(*param+regex->len,0,1);
  73. fixup_regexp_none(param,1);
  74. retval=search_f(msg, *param, NULL);
  75. fixup_free_regexp_none(param,1);
  76. pkg_free(param);
  77. return retval;
  78. }
  79. int is_privacy_api(struct sip_msg *msg, str* privacy_type){
  80. int retval;
  81. void **param=pkg_malloc(sizeof(void*));
  82. *param=pkg_malloc(privacy_type->len+1);
  83. memcpy(*param,privacy_type->s,privacy_type->len);
  84. memset(*param+privacy_type->len,0,1);
  85. fixup_privacy(param, 1);
  86. retval = is_privacy_f(msg, *param, NULL);
  87. pkg_free(param);
  88. return retval;
  89. }
  90. /*
  91. * Function to load the textops api.
  92. */
  93. int bind_textops(textops_api_t *tob){
  94. if(tob==NULL){
  95. LM_WARN("textops_binds: Cannot load textops API into a NULL pointer\n");
  96. return -1;
  97. }
  98. tob->append_hf=append_hf_api;
  99. tob->remove_hf=remove_hf_api;
  100. tob->search_append=search_append_api;
  101. tob->search=search_api;
  102. tob->is_privacy=is_privacy_api;
  103. return 0;
  104. }