parse_msg_rules.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_common_rules.h>
  26. #include <xcap/parse_msg_rules.h>
  27. #include <xcap/xcap_result_codes.h>
  28. #include <cds/dstring.h>
  29. #include <cds/memory.h>
  30. #include <cds/logger.h>
  31. #include <cds/list.h>
  32. #include <string.h>
  33. #include <xcap/xml_utils.h>
  34. char *msg_rules_ns = NULL;
  35. static int str2msg_handling(const char *s, msg_handling_t *dst)
  36. {
  37. if (!s) return RES_INTERNAL_ERR;
  38. if (strcmp(s, "allow") == 0) {
  39. *dst = msg_handling_allow;
  40. return 0;
  41. }
  42. if (strcmp(s, "block") == 0) {
  43. *dst = msg_handling_block;
  44. return 0;
  45. }
  46. /* if (strcmp(s, "polite-block") == 0) {
  47. *dst = msg_handling_polite_block;
  48. return 0;
  49. }
  50. if (strcmp(s, "confirm") == 0) {
  51. *dst = msg_handling_confirm;
  52. return 0;
  53. }*/
  54. ERROR_LOG("invalid im-handling value: \'%s\'\n", s);
  55. return RES_INTERNAL_ERR;
  56. }
  57. static int read_msg_actions(xmlNode *an, cp_actions_t **dst)
  58. {
  59. xmlNode *n;
  60. const char *s;
  61. int res = RES_OK;
  62. if ((!an) || (!dst)) return RES_INTERNAL_ERR;
  63. *dst = (cp_actions_t*)cds_malloc(sizeof(cp_actions_t));
  64. if (!(*dst)) return RES_MEMORY_ERR;
  65. memset(*dst, 0, sizeof(cp_actions_t));
  66. n = find_node(an, "im-handling", msg_rules_ns);
  67. if (n) {
  68. /* may be only one sub-handling node? */
  69. s = get_node_value(n);
  70. (*dst)->unknown = create_unknown(sizeof(msg_handling_t));
  71. if (!(*dst)->unknown) return RES_MEMORY_ERR;
  72. res = str2msg_handling(s, (msg_handling_t*)(*dst)->unknown->data);
  73. }
  74. return res;
  75. }
  76. int parse_msg_rules(const char *data, int dsize, cp_ruleset_t **dst)
  77. {
  78. return parse_common_rules(data, dsize, dst,
  79. read_msg_actions, free_msg_actions);
  80. }