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

Function set_node_content

modules/xml/xml.c:767–815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

765#define CDATA_SUFFIX_LEN (sizeof(CDATA_SUFFIX_S) - 1)
766
767static int set_node_content(xmlNode *node, str new_content, xmlDoc *xml_doc)
768{
769 xmlNode *n_it, *tmp = NULL, *new_txt;
770 int set = 0;
771
772 if ((new_content.len > CDATA_PREFIX_LEN + CDATA_SUFFIX_LEN) &&
773 str_strstr(&new_content, &str_init(CDATA_PREFIX_S)))
774 return set_node_content_w_cdata(node, new_content, xml_doc);
775
776 /* remove all text and CDATA nodes */
777 if (!new_content.s)
778 set = 1;
779
780 for (n_it = node->children; n_it; n_it = tmp) {
781 tmp = n_it->next;
782
783 if (n_it->type == XML_TEXT_NODE || n_it->type == XML_CDATA_SECTION_NODE) {
784 if (!set) {
785 if (n_it->type == XML_CDATA_SECTION_NODE) {
786 xmlUnlinkNode(n_it);
787 xmlFreeNode(n_it);
788 } else {
789 /* replace existing node content with given string */
790 xmlNodeSetContentLen(n_it,
791 BAD_CAST new_content.s, new_content.len);
792 set = 1;
793 }
794 } else {
795 /* remove any other text or CDATA node */
796 xmlUnlinkNode(n_it);
797 xmlFreeNode(n_it);
798 }
799 }
800 }
801
802 /* no existing text nodes, create one */
803 if (new_content.s && !set) {
804 if ((new_txt = xmlNewTextLen(BAD_CAST new_content.s, new_content.len)) == NULL) {
805 LM_ERR("Unable to create text node\n");
806 return -1;
807 }
808 if (!xmlAddChild(node, new_txt)) {
809 LM_ERR("Unable to add text node\n");
810 return -1;
811 }
812 }
813
814 return 0;
815}
816
817int pv_set_xml(struct sip_msg* msg, pv_param_t* pvp, int flag, pv_value_t* val)
818{

Callers 1

pv_set_xmlFunction · 0.85

Calls 2

str_strstrFunction · 0.85
set_node_content_w_cdataFunction · 0.85

Tested by

no test coverage detected