/* * (C) 2012-2013 by Pablo Neira Ayuso * (C) 2013 by Arturo Borrero Gonzalez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This code has been sponsored by Sophos Astaro */ #include "internal.h" #include "expr_ops.h" #include #include #include struct nft_rule_expr *nft_mxml_expr_parse(mxml_node_t *node) { mxml_node_t *tree; struct nft_rule_expr *e; const char *expr_name; char *xml_text; int ret; expr_name = mxmlElementGetAttr(node, "type"); if (expr_name == NULL) goto err; e = nft_rule_expr_alloc(expr_name); if (e == NULL) goto err; xml_text = mxmlSaveAllocString(node, MXML_NO_CALLBACK); if (xml_text == NULL) goto err_expr; tree = mxmlLoadString(NULL, xml_text, MXML_OPAQUE_CALLBACK); free(xml_text); if (tree == NULL) goto err_expr; ret = e->ops->xml_parse(e, tree); mxmlDelete(tree); return ret < 0 ? NULL : e; err_expr: nft_rule_expr_free(e); err: mxmlDelete(tree); errno = EINVAL; return NULL; }