2 * Copyright (C) 2005 iptelorg GmbH
4 * This file is part of ser, a free SIP server.
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
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:
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.
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
26 #include <xcap/parse_common_rules.h>
27 #include <xcap/parse_msg_rules.h>
28 #include <xcap/xcap_result_codes.h>
30 #include <cds/dstring.h>
31 #include <cds/memory.h>
32 #include <cds/logger.h>
36 #include <xcap/xml_utils.h>
38 char *msg_rules_ns = NULL;
40 static int str2msg_handling(const char *s, msg_handling_t *dst)
42 if (!s) return RES_INTERNAL_ERR;
44 if (strcmp(s, "allow") == 0) {
45 *dst = msg_handling_allow;
48 if (strcmp(s, "block") == 0) {
49 *dst = msg_handling_block;
52 /* if (strcmp(s, "polite-block") == 0) {
53 *dst = msg_handling_polite_block;
56 if (strcmp(s, "confirm") == 0) {
57 *dst = msg_handling_confirm;
60 ERROR_LOG("invalid im-handling value: \'%s\'\n", s);
61 return RES_INTERNAL_ERR;
64 static int read_msg_actions(xmlNode *an, cp_actions_t **dst)
69 if ((!an) || (!dst)) return RES_INTERNAL_ERR;
71 *dst = (cp_actions_t*)cds_malloc(sizeof(cp_actions_t));
72 if (!(*dst)) return RES_MEMORY_ERR;
73 memset(*dst, 0, sizeof(cp_actions_t));
75 n = find_node(an, "im-handling", msg_rules_ns);
77 /* may be only one sub-handling node? */
78 s = get_node_value(n);
79 (*dst)->unknown = create_unknown(sizeof(msg_handling_t));
80 if (!(*dst)->unknown) return RES_MEMORY_ERR;
81 res = str2msg_handling(s, (msg_handling_t*)(*dst)->unknown->data);
87 int parse_msg_rules(const char *data, int dsize, cp_ruleset_t **dst)
89 return parse_common_rules(data, dsize, dst,
90 read_msg_actions, free_msg_actions);