| 815 | } |
| 816 | |
| 817 | int pv_set_xml(struct sip_msg* msg, pv_param_t* pvp, int flag, pv_value_t* val) |
| 818 | { |
| 819 | xml_path_t *path = NULL; |
| 820 | xml_object_t *obj; |
| 821 | xmlDoc *new_doc = NULL; |
| 822 | xmlNode *root, *node = NULL; |
| 823 | str empty_str = {0,0}; |
| 824 | char *attr_name_s, *attr_val_s; |
| 825 | |
| 826 | path = (xml_path_t *)pvp->pvn.u.dname; |
| 827 | if (!path) { |
| 828 | LM_BUG("No path for xml var\n"); |
| 829 | return -1; |
| 830 | } |
| 831 | |
| 832 | /* get the object refered in this xml var */ |
| 833 | obj = get_xml_obj(path); |
| 834 | |
| 835 | if (path_eval_vars(msg, path) < 0) |
| 836 | return -1; |
| 837 | |
| 838 | if (obj && obj->xml_doc && path->elements) { |
| 839 | root = xmlDocGetRootElement(obj->xml_doc); |
| 840 | node = get_node_by_path(root, path->elements); |
| 841 | if (!node) { |
| 842 | LM_NOTICE("Element not found\n"); |
| 843 | return -1; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | if (!val || val->flags & PV_VAL_NULL) { |
| 848 | if (!obj) { |
| 849 | LM_ERR("Uninitialized xml object: %.*s\n", path->obj_name.len, |
| 850 | path->obj_name.s); |
| 851 | return -1; |
| 852 | } |
| 853 | |
| 854 | switch (path->access_mode) { |
| 855 | case ACCESS_EL: |
| 856 | if (!path->elements) { /* we only have the object name in path */ |
| 857 | if (!obj->xml_doc) /* attempted to clear empty xml object */ |
| 858 | return 0; |
| 859 | |
| 860 | /* clear the entire object */ |
| 861 | xmlFreeDoc(obj->xml_doc); |
| 862 | obj->xml_doc = NULL; |
| 863 | } else { |
| 864 | /* delete node */ |
| 865 | if (!node) { |
| 866 | LM_NOTICE("Element not found\n"); |
| 867 | return -1; |
| 868 | } |
| 869 | |
| 870 | xmlUnlinkNode(node); |
| 871 | xmlFreeNode(node); |
| 872 | } |
| 873 | break; |
| 874 | case ACCESS_EL_VAL: |
nothing calls this directly
no test coverage detected