| 852 | } |
| 853 | |
| 854 | int |
| 855 | cib_process_xpath(const char *op, int options, const char *section, xmlNode * req, xmlNode * input, |
| 856 | xmlNode * existing_cib, xmlNode ** result_cib, xmlNode ** answer) |
| 857 | { |
| 858 | int lpc = 0; |
| 859 | int max = 0; |
| 860 | int rc = pcmk_ok; |
| 861 | gboolean is_query = safe_str_eq(op, CIB_OP_QUERY); |
| 862 | |
| 863 | xmlXPathObjectPtr xpathObj = NULL; |
| 864 | |
| 865 | crm_trace("Processing \"%s\" event", op); |
| 866 | |
| 867 | if (is_query) { |
| 868 | xpathObj = xpath_search(existing_cib, section); |
| 869 | } else { |
| 870 | xpathObj = xpath_search(*result_cib, section); |
| 871 | } |
| 872 | |
| 873 | if (xpathObj != NULL && xpathObj->nodesetval != NULL) { |
| 874 | max = xpathObj->nodesetval->nodeNr; |
| 875 | } |
| 876 | |
| 877 | if (max < 1 && safe_str_eq(op, CIB_OP_DELETE)) { |
| 878 | crm_debug("%s was already removed", section); |
| 879 | |
| 880 | } else if (max < 1) { |
| 881 | crm_debug("%s: %s does not exist", op, section); |
| 882 | rc = -ENXIO; |
| 883 | |
| 884 | } else if (is_query) { |
| 885 | if (max > 1) { |
| 886 | *answer = create_xml_node(NULL, "xpath-query"); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | for (lpc = 0; lpc < max; lpc++) { |
| 891 | xmlChar *path = NULL; |
| 892 | xmlNode *match = getXpathResult(xpathObj, lpc); |
| 893 | |
| 894 | if (match == NULL) { |
| 895 | continue; |
| 896 | } |
| 897 | |
| 898 | path = xmlGetNodePath(match); |
| 899 | crm_debug("Processing %s op for %s (%s)", op, section, path); |
| 900 | free(path); |
| 901 | |
| 902 | if (safe_str_eq(op, CIB_OP_DELETE)) { |
| 903 | free_xml(match); |
| 904 | if ((options & cib_multiple) == 0) { |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | } else if (safe_str_eq(op, CIB_OP_MODIFY)) { |
| 909 | if (update_xml_child(match, input) == FALSE) { |
| 910 | rc = -ENXIO; |
| 911 | } else if ((options & cib_multiple) == 0) { |
no test coverage detected