- xpath_ctx->node = base_nodes->nodeTab[i];
-
- /* instance has to be an xpath expression */
- if (xpath->instance != NULL)
- {
- instance_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->instance);
- if (instance_node_obj == NULL)
- continue; /* error is logged already */
-
- instance_node = instance_node_obj->nodesetval;
- tmp_size = (instance_node) ? instance_node->nodeNr : 0;
-
- if ( (tmp_size == 0) && (total_nodes > 1) )
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression for 'Instance' \"%s\" doesn't match "
- "any of the nodes. Skipping the node - %s",
- xpath->instance, base_nodes->nodeTab[i]->name);
- xmlXPathFreeObject (instance_node_obj);
- continue;
- }
-
- if (tmp_size > 1)
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression for 'Instance' \"%s\" is expected "
- "to return only one text node. Skipping the node - %s",
- xpath->instance, base_nodes->nodeTab[i]->name);
- xmlXPathFreeObject (instance_node_obj);
- continue;
- }
-
- /* ignoring the element if other than textnode/attribute */
- if (cx_if_not_text_node(instance_node->nodeTab[0]))
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression \"%s\" is expected to return only text node "
- "which is not the case. Skipping the node - %s",
- xpath->instance, base_nodes->nodeTab[i]->name);
- xmlXPathFreeObject (instance_node_obj);
- continue;
- }
- } /* if (xpath->instance != NULL) */
-
- for (j = 0; j < xpath->values_len; j++)
- {
- xmlXPathObjectPtr values_node_obj;
-
- values_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST xpath->values[j].path);
- if (values_node_obj == NULL)
- continue; /* Error already logged. */
-
- values_node = values_node_obj->nodesetval;
- tmp_size = (values_node) ? values_node->nodeNr : 0;
-
- if (tmp_size == 0)
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression \"%s\" doesn't match any of the nodes. "
- "Skipping...", xpath->values[j].path);
- xmlXPathFreeObject (values_node_obj);
- continue;
- }
-
- if (tmp_size > 1)
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression \"%s\" is expected to return "
- "only one node. Skipping...", xpath->values[j].path);
- xmlXPathFreeObject (values_node_obj);
- continue;
- }
-
- /* ignoring the element if other than textnode/attribute*/
- if (cx_if_not_text_node(values_node->nodeTab[0]))
- {
- WARNING ("curl_xml plugin: "
- "relative xpath expression \"%s\" is expected to return "
- "only text/attribute node which is not the case. Skipping...",
- xpath->values[j].path);
- xmlXPathFreeObject (values_node_obj);
- continue;
- }
-
- vl.values = (value_t *) malloc (sizeof (value_t) * vl.values_len);
- if (vl.values == NULL)
- {
- ERROR ("curl_xml plugin: malloc failed.");
- xmlXPathFreeObject (base_node_obj);
- xmlXPathFreeObject (instance_node_obj);
- xmlXPathFreeObject (values_node_obj);
- return (-1);
- }
-
- node_value = (char *) xmlNodeGetContent(values_node->nodeTab[0]);
- switch (ds->ds[j].type)
- {
- case DS_TYPE_COUNTER:
- vl.values[j].counter = atoi(node_value);
- break;
- case DS_TYPE_DERIVE:
- vl.values[j].derive = atoi(node_value);
- break;
- case DS_TYPE_ABSOLUTE:
- vl.values[j].absolute = atoi(node_value);
- break;
- case DS_TYPE_GAUGE:
- vl.values[j].absolute = atoi(node_value);
- }
-
- if (xpath->instance_prefix != NULL)
- {
- if (instance_node != NULL)
- ssnprintf (vl.type_instance, sizeof (vl.type_instance),"%s-%s",
- xpath->instance_prefix, (char *) xmlNodeGetContent(instance_node->nodeTab[0]));
- else
- sstrncpy (vl.type_instance, xpath->instance_prefix,
- sizeof (vl.type_instance));
- }
- else
- {
- /* If instance_prefix and instance_node are NULL, then
- * don't set the type_instance */
- if (instance_node != NULL)
- sstrncpy (vl.type_instance, (char *) xmlNodeGetContent(instance_node->nodeTab[0]),
- sizeof (vl.type_instance));
- else
- vl.type_instance[0] = 0;
- }
-
- /* free up object */
- xmlXPathFreeObject (values_node_obj);
-
- /* We have reached here which means that
- * we have got something to work */
- status = 0;
- } /* for (j = 0; j < xpath->values_len; j++) */
-
- /* submit the values */
- if (vl.values)
- plugin_dispatch_values (&vl);
-
- sfree(vl.values);
- if (instance_node_obj != NULL)
- xmlXPathFreeObject (instance_node_obj);
- }