/** free node */ void xml_free_node( XML_NODE* node ) { XML_NODE* n; if (node == NULL) return; n = node->first_child; while (n != NULL) { XML_NODE* m; m = n->next_sibl; xml_free_node(n); n = m; } xml_free_attr(node->attr_list); if (node->data != NULL) { BMSfreeMemoryArray(&node->data); } assert(node->name != NULL); BMSfreeMemoryArray(&node->name); BMSfreeMemory(&node); #if 0 if (n != NULL) { xml_free_node(n->first_child); xml_free_node(n->next_sibl); xml_free_attr(n->attr_list); if (n->data != NULL) { BMSfreeMemoryArray(&n->data); } assert(n->name != NULL); BMSfreeMemoryArray(&n->name); BMSfreeMemory(&n); } #endif }
int xml_put_attr_ic ( XML_ITEM *item, const char *name, const char *value, Bool ignore_case) { int feedback = 0; XML_ATTR *attr; ASSERT (item); ASSERT (name); attr = xml_attr_ic (item, name, ignore_case); if (attr) if (value) /* Value specified - update attr */ { mem_free (attr-> value); attr-> value = mem_strdup (value); } else { xml_free_attr (attr); /* No value - delete attribute */ feedback = -1; } else if (value) /* Value specified - update attr */ { list_create (attr, sizeof (XML_ATTR)); if (attr) { attr-> name = mem_strdup (name); attr-> value = mem_strdup (value); attr-> parent = item; list_relink_before (attr, &item-> attrs); feedback = 1; } } return (feedback); }
void xml_free ( XML_ITEM *item) { ASSERT (item); /* Free attribute nodes for the item */ while (!list_empty (&item-> attrs)) xml_free_attr (item-> attrs.next); /* Free child nodes for the item */ while (!list_empty (&item-> children)) xml_free (item-> children.next); /* Now free this item itself */ list_unlink (item); /* Unlink from its parent list */ mem_free (item-> name); /* Free strings, if not null */ mem_free (item-> value); mem_free (item); /* And free the item itself */ }
/******************************************************************** * FUNCTION xml_msg_clean_defns_attr * * Get rid of an xmlns=foo default attribute * * INPUTS: * attrs == xmlns_attrs_t Q to process * * OUTPUTS: * *attrs will be cleaned as needed, * * RETURNS: * status *********************************************************************/ status_t xml_msg_clean_defns_attr (xml_attrs_t *attrs) { xml_attr_t *attr, *nextattr; uint32 len, len2; #ifdef DEBUG if (!attrs) { return SET_ERROR(ERR_INTERNAL_PTR); } #endif len = xml_strlen(XMLNS); for (attr = (xml_attr_t *)xml_first_attr(attrs); attr != NULL; attr = nextattr) { nextattr = (xml_attr_t *)xml_next_attr(attr); len2 = xml_strlen(attr->attr_qname); if (len2 >= len) { if (!xml_strncmp(attr->attr_qname, XMLNS, len)) { if (len == len2) { /* this xmlns=foo is getting toosed so * the netconf NSID can be the default */ dlq_remove(attr); xml_free_attr(attr); return NO_ERR; } /* else xmlns:foo=bar found */ } /* else not xmlns */ } /* else not 'xmlns' */ } return NO_ERR; } /* xml_msg_clean_defns_attr */
/** free attribute */ static void xml_free_attr( XML_ATTR* attr ) { XML_ATTR* a; a = attr; while (a != NULL) { XML_ATTR* b; b = a->next; assert(a->name != NULL); assert(a->value != NULL); BMSfreeMemoryArray(&a->name); BMSfreeMemoryArray(&a->value); BMSfreeMemory(&a); a = b; } #if 0 if (a != NULL) { xml_free_attr(a->next); assert(a->name != NULL); assert(a->value != NULL); BMSfreeMemoryArray(&a->name); BMSfreeMemoryArray(&a->value); BMSfreeMemory(&a); } #endif }
/******************************************************************** * FUNCTION mgr_rpc_send_request * * Send an <rpc> request to the agent on the specified session * non-blocking send, reply function will be called when * one is received or a timeout occurs * * INPUTS: * scb == session control block * req == request to send * rpyfn == reply callback function * * RETURNS: * status *********************************************************************/ status_t mgr_rpc_send_request (ses_cb_t *scb, mgr_rpc_req_t *req, mgr_rpc_cbfn_t rpyfn) { xml_msg_hdr_t msg; xml_attr_t *attr; status_t res; boolean anyout; xmlns_id_t nc_id; #ifdef DEBUG if (!scb || !req || !rpyfn) { return SET_ERROR(ERR_INTERNAL_PTR); } #endif #ifdef MGR_HELLO_DEBUG log_debug2("\nmgr sending RPC request %s on session %d", req->msg_id, scb->sid); #endif anyout = FALSE; xml_msg_init_hdr(&msg); nc_id = xmlns_nc_id(); /* make sure the message-id attribute is not already present */ attr = xml_find_attr_q(&req->attrs, 0, NCX_EL_MESSAGE_ID); if (attr) { dlq_remove(attr); xml_free_attr(attr); } /* setup the prefix map with the NETCONF (and maybe NCX) namespace */ res = xml_msg_build_prefix_map(&msg, &req->attrs, FALSE, (req->data->nsid == xmlns_ncx_id())); /* add the message-id attribute */ if (res == NO_ERR) { res = xml_add_attr(&req->attrs, 0, NCX_EL_MESSAGE_ID, req->msg_id); } /* set perf timestamp in case response timing active */ gettimeofday(&req->perfstarttime, NULL); /* send the <?xml?> directive */ if (res == NO_ERR) { res = ses_start_msg(scb); } /* start the <rpc> element */ if (res == NO_ERR) { anyout = TRUE; xml_wr_begin_elem_ex(scb, &msg, 0, nc_id, NCX_EL_RPC, &req->attrs, ATTRQ, 0, START); } /* send the method and parameters */ if (res == NO_ERR) { xml_wr_full_val(scb, &msg, req->data, NCX_DEF_INDENT); } /* finish the <rpc> element */ if (res == NO_ERR) { xml_wr_end_elem(scb, &msg, nc_id, NCX_EL_RPC, 0); } /* finish the message */ if (anyout) { ses_finish_msg(scb); } if (res == NO_ERR) { req->replycb = rpyfn; add_request(scb, req); } xml_msg_clean_hdr(&msg); return res; } /* mgr_rpc_send_request */