MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / pv_get_xml

Function pv_get_xml

modules/xml/xml.c:492–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490static str res_buf;
491
492int pv_get_xml(struct sip_msg* msg, pv_param_t* pvp, pv_value_t* res)
493{
494 xml_path_t *path = NULL;
495 xml_object_t *obj;
496 xmlNode *root = NULL, *node;
497 xmlBufferPtr xml_buf = NULL;
498 xmlAttr *attr;
499 char *xml_buf_s;
500 int xml_buf_len;
501
502 path = (xml_path_t *)pvp->pvn.u.dname;
503 if (!path) {
504 LM_BUG("No path for xml var\n");
505 return pv_get_null( msg, pvp, res);
506 }
507
508 /* get the object refered in this xml var */
509 obj = get_xml_obj(path);
510 if (!obj) {
511 LM_DBG("Unknown object <%.*s>\n", path->obj_name.len, path->obj_name.s);
512 return pv_get_null( msg, pvp, res);
513 }
514
515 if (!obj->xml_doc) {
516 LM_DBG("Empty xml object\n");
517 return pv_get_null( msg, pvp, res);
518 }
519
520 if (path_eval_vars(msg, path) < 0)
521 return -1;
522
523 root = xmlDocGetRootElement(obj->xml_doc);
524 if (path->elements) {
525 node = get_node_by_path(root, path->elements);
526 if (!node) {
527 LM_DBG("Element not found\n");
528 return pv_get_null( msg, pvp, res);
529 }
530 } else
531 /* in case of dumping entire object, we do this from the root node */
532 node = root;
533
534 switch (path->access_mode) {
535 case ACCESS_EL:
536 if (!path->elements) {
537 xmlDocDumpMemory(obj->xml_doc, (xmlChar **)&xml_buf_s, &xml_buf_len);
538 /* libxml seems to place an unnecessary newline at the end of the doc dump */
539 if (xml_buf_s[xml_buf_len-1] == '\n')
540 xml_buf_len--;
541 } else {
542 xml_buf = xmlBufferCreate();
543 if (!xml_buf) {
544 LM_ERR("Unable to obtain xml buffer\n");
545 return pv_get_null( msg, pvp, res);
546 }
547
548 xml_buf_len = xmlNodeDump(xml_buf, obj->xml_doc, node, 0, 0);
549 if (xml_buf_len == -1) {

Callers

nothing calls this directly

Calls 7

pv_get_nullFunction · 0.85
get_xml_objFunction · 0.85
path_eval_varsFunction · 0.85
get_node_by_pathFunction · 0.85
pkg_str_extendFunction · 0.85
get_node_attrFunction · 0.85
get_node_contentFunction · 0.70

Tested by

no test coverage detected