parse_pres_rules.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2005 iptelorg GmbH
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * For a license to use the ser software under conditions
  12. * other than those described here, or to purchase support for this
  13. * software, please contact iptel.org by e-mail at the following addresses:
  14. * [email protected]
  15. *
  16. * ser is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. */
  25. #include <xcap/parse_pres_rules.h>
  26. #include <xcap/xcap_result_codes.h>
  27. #include <cds/dstring.h>
  28. #include <cds/memory.h>
  29. #include <cds/logger.h>
  30. #include <cds/list.h>
  31. #include <string.h>
  32. #include <xcap/xml_utils.h>
  33. char *pres_rules_ns = NULL;
  34. static int str2sub_handling(const char *s, sub_handling_t *dst)
  35. {
  36. if (!s) return RES_INTERNAL_ERR;
  37. if (strcmp(s, "allow") == 0) {
  38. *dst = sub_handling_allow;
  39. return 0;
  40. }
  41. if (strcmp(s, "block") == 0) {
  42. *dst = sub_handling_block;
  43. return 0;
  44. }
  45. if (strcmp(s, "polite-block") == 0) {
  46. *dst = sub_handling_polite_block;
  47. return 0;
  48. }
  49. if (strcmp(s, "confirm") == 0) {
  50. *dst = sub_handling_confirm;
  51. return 0;
  52. }
  53. ERROR_LOG("invalid sub-handling value: \'%s\'\n", s);
  54. return RES_INTERNAL_ERR;
  55. }
  56. static int read_pres_actions(xmlNode *an, cp_actions_t **dst)
  57. {
  58. xmlNode *n;
  59. const char *s;
  60. int res = RES_OK;
  61. if ((!an) || (!dst)) return RES_INTERNAL_ERR;
  62. *dst = (cp_actions_t*)cds_malloc(sizeof(cp_actions_t));
  63. if (!(*dst)) return RES_MEMORY_ERR;
  64. memset(*dst, 0, sizeof(cp_actions_t));
  65. n = find_node(an, "sub-handling", pres_rules_ns);
  66. if (n) {
  67. /* may be only one sub-handling node? */
  68. s = get_node_value(n);
  69. (*dst)->unknown = create_unknown(sizeof(sub_handling_t));
  70. if (!(*dst)->unknown) return RES_MEMORY_ERR;
  71. res = str2sub_handling(s, (sub_handling_t*)(*dst)->unknown->data);
  72. }
  73. return res;
  74. }
  75. int parse_pres_rules(const char *data, int dsize, cp_ruleset_t **dst)
  76. {
  77. return parse_common_rules(data, dsize, dst, read_pres_actions, free_pres_actions);
  78. }