/******************************************************************** * FUNCTION rpc_err_free_info * * Clean and free an rpc_err_info_t struct * * INPUTS: * errinfo == rpc_err_info_t struct to clean and free * RETURNS: * none *********************************************************************/ void rpc_err_free_info (rpc_err_info_t *errinfo) { #ifdef DEBUG if (!errinfo) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (errinfo->badns) { m__free(errinfo->badns); } if (errinfo->dname) { m__free(errinfo->dname); } if (errinfo->dval) { m__free(errinfo->dval); } switch (errinfo->val_btype) { case NCX_BT_ANY: case NCX_BT_CONTAINER: case NCX_BT_CHOICE: case NCX_BT_LIST: if (errinfo->v.cpxval) { val_free_value((val_value_t *)errinfo->v.cpxval); } break; default: ; } m__free(errinfo); } /* rpc_err_free_info */
/******************************************************************** * FUNCTION grp_free_template * * Scrub the memory in a grp_template_t by freeing all * the sub-fields and then freeing the entire struct itself * The struct must be removed from any queue it is in before * this function is called. * * INPUTS: * grp == grp_template_t data structure to free *********************************************************************/ void grp_free_template (grp_template_t *grp) { #ifdef DEBUG if (!grp) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (grp->name) { m__free(grp->name); } if (grp->descr) { m__free(grp->descr); } if (grp->ref) { m__free(grp->ref); } typ_clean_typeQ(&grp->typedefQ); grp_clean_groupingQ(&grp->groupingQ); obj_clean_datadefQ(&grp->datadefQ); ncx_clean_appinfoQ(&grp->appinfoQ); m__free(grp); } /* grp_free_template */
/******************************************************************** * FUNCTION rpc_err_clean_record * * Clean an rpc_err_rec_t struct * * INPUTS: * err == rpc_err_rec_t struct to clean * RETURNS: * none *********************************************************************/ void rpc_err_clean_record (rpc_err_rec_t *err) { rpc_err_info_t *errinfo; #ifdef DEBUG if (!err) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif err->error_res = NO_ERR; err->error_id = RPC_ERR_NONE; err->error_type = NCX_LAYER_NONE; err->error_severity = RPC_ERR_SEV_NONE; err->error_tag = NULL; err->error_app_tag = NULL; if (err->error_path) { m__free(err->error_path); err->error_path = NULL; } if (err->error_message) { m__free(err->error_message); } err->error_message_lang = NULL; while (!dlq_empty(&err->error_info)) { errinfo = (rpc_err_info_t *)dlq_deque(&err->error_info); rpc_err_free_info(errinfo); } } /* rpc_err_clean_record */
/******************************************************************** * FUNCTION ncx_free_feature * * Free a malloced ncx_feature_t struct * * INPUTS: * feature == struct to free * *********************************************************************/ void ncx_free_feature (ncx_feature_t *feature) { #ifdef DEBUG if (!feature) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (feature->name) { m__free(feature->name); } if (feature->descr) { m__free(feature->descr); } if (feature->ref) { m__free(feature->ref); } ncx_clean_iffeatureQ(&feature->iffeatureQ); ncx_clean_appinfoQ(&feature->appinfoQ); m__free(feature); } /* ncx_free_feature */
static void free_callback_set( agt_cb_queue_notification_set_t* cbSet ) { if ( cbSet->modname ) { m__free( cbSet->modname ); } m__free( cbSet ); }
static void free_callback_set( agt_cb_commit_complete_set_t* cbSet ) { if ( cbSet->modname ) { m__free( cbSet->modname ); } m__free( cbSet ); }
/******************************************************************** * FUNCTION yangapi_free_keyval * * Free a YANGAPI keyval * * INPUTS: * param == Yuma REST-API keyval to free * RETURNS: * none *********************************************************************/ void yangapi_free_keyval (yangapi_keyval_t *keyval) { if (!keyval) { return; } m__free(keyval->value); m__free(keyval); } /* yangapi_free_keyval */
/******************************************************************** * FUNCTION agt_ses_set_dummy_session_acm * * Set the session ID and username of the user that * will be responsible for the rollback if needed * * INPUTS: * dummy_session == session control block to change * use_sid == Session ID to use for the rollback * * RETURNS: * status *********************************************************************/ status_t agt_ses_set_dummy_session_acm (ses_cb_t *dummy_session, ses_id_t use_sid) { ses_cb_t *scb; assert( dummy_session && "dummy_session is NULL!" ); if (!agt_ses_init_done) { agt_ses_init(); } scb = agtses[use_sid]; if (scb == NULL) { return ERR_NCX_INVALID_VALUE; } dummy_session->rollback_sid = use_sid; /*TODO Quick fix for confirmed-commit/rollback bug. */ /* Needs further investigation. */ dummy_session->sid = use_sid; if (scb == dummy_session) { return NO_ERR; /* skip -- nothing to do */ } if (dummy_session->username && scb->username) { m__free(dummy_session->username); dummy_session->username = NULL; } if (scb->username) { dummy_session->username = xml_strdup(scb->username); if (dummy_session->username == NULL) { return ERR_INTERNAL_MEM; } } if (dummy_session->peeraddr && scb->peeraddr) { m__free(dummy_session->peeraddr); dummy_session->peeraddr = NULL; } if (scb->peeraddr) { dummy_session->peeraddr = xml_strdup(scb->peeraddr); if (dummy_session->peeraddr == NULL) { return ERR_INTERNAL_MEM; } } return NO_ERR; } /* agt_ses_set_dummy_session_acm */
/******************************************************************** * FUNCTION yangapi_free_param * * Free a YANGAPI parameter * * INPUTS: * param == Yuma REST-API parameter to free * RETURNS: * none *********************************************************************/ void yangapi_free_param (yangapi_param_t *param) { if (!param) { return; } m__free(param->name); m__free(param->value); m__free(param); } /* yangapi_free_param */
/******************************************************************** * FUNCTION agt_cfg_free_auditrec * * Free all the memory used by the specified agt_cfg_audit_rec_t * * INPUTS: * auditrec == agt_cfg_audit_rec_t to clean and delete * * RETURNS: * none *********************************************************************/ void agt_cfg_free_auditrec (agt_cfg_audit_rec_t *auditrec) { if (auditrec == NULL) { return; } if (auditrec->target) { m__free(auditrec->target); } m__free(auditrec); } /* agt_cfg_free_auditrec */
/******************************************************************** * FUNCTION free_event_cb * * Clean and free an event control block * * INPUTS: * cb == control block to free *********************************************************************/ static void free_event_cb (event_cb_t *cb) { if (cb == NULL) { return; } m__free(cb->modname); m__free(cb->event); m__free(cb); } /* free_event_cb */
/******************************************************************** * FUNCTION free_dynlib_cb * * Clean and free a new dynamic library control block * * INPUTS: * dynlib == dynamic library control block to free *********************************************************************/ static void free_dynlib_cb (agt_dynlib_cb_t *dynlib) { if (dynlib->modname) { m__free(dynlib->modname); } if (dynlib->revision) { m__free(dynlib->revision); } m__free(dynlib); } /* free_dynlib_cb */
/******************************************************************** * FUNCTION free_feature_entry * * Free a feature_entry_t * * INPUTS: * feature_entry == feature entry struct to free *********************************************************************/ static void free_feature_entry (feature_entry_t *feature_entry) { if (feature_entry->modname) { m__free(feature_entry->modname); } if (feature_entry->feature) { m__free(feature_entry->feature); } m__free(feature_entry); } /* free_feature_entry */
/******************************************************************** * FUNCTION free_alias * * Free the alias record * * INPUTS: * alias == pointer to alias record to free *********************************************************************/ static void free_alias (alias_cb_t *alias) { if (alias == NULL) { return; } if (alias->name != NULL) { m__free(alias->name); } if (alias->value != NULL) { m__free(alias->value); } m__free(alias); } /* free_alias */
/******************************************************************** * FUNCTION mgr_rpc_new_request * * Malloc and initialize a new mgr_rpc_req_t struct * * INPUTS: * scb == session control block * * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ mgr_rpc_req_t * mgr_rpc_new_request (ses_cb_t *scb) { mgr_scb_t *mscb; mgr_rpc_req_t *req; char numbuff[NCX_MAX_NUMLEN]; req = m__getObj(mgr_rpc_req_t); if (!req) { return NULL; } memset(req, 0x0, sizeof(mgr_rpc_req_t)); mscb = mgr_ses_get_mscb(scb); sprintf(numbuff, "%u", mscb->next_id); if (mscb->next_id >= MGR_MAX_REQUEST_ID) { mscb->next_id = 0; } else { mscb->next_id++; } req->msg_id = xml_strdup((const xmlChar *)numbuff); if (req->msg_id) { xml_msg_init_hdr(&req->mhdr); xml_init_attrs(&req->attrs); } else { m__free(req); req = NULL; } return req; } /* mgr_rpc_new_request */
/******************************************************************** * FUNCTION set_config_path * * Change or set the config path prompt * * INPUTS: * session_cb == session control block to use * * RETURNS: * status *********************************************************************/ static status_t set_config_path (session_cb_t *session_cb) { status_t res = NO_ERR; /* update the prompt path string */ m__free(session_cb->config_path); session_cb->config_path = NULL; if (session_cb->config_ecurval) { ncx_instfmt_t format = NCX_IFMT_CLI2; if (session_cb->prompt_type == HELP_MODE_FULL) { format = NCX_IFMT_CLI; } res = val_gen_instance_id(NULL, session_cb->config_ecurval, format, &session_cb->config_path); } else if (session_cb->config_curobj) { if (session_cb->prompt_type == HELP_MODE_FULL) { res = obj_gen_object_id_xpath(session_cb->config_curobj, &session_cb->config_path); } else { res = obj_gen_object_id(session_cb->config_curobj, &session_cb->config_path); } } return res; } /* set_config_path */
/******************************************************************** * FUNCTION agt_cfg_new_auditrec * * Malloc and initialize a new agt_cfg_audit_rec_t struct * * INPUTS: * target == i-i string of edit target * editop == edit operation enum * * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ agt_cfg_audit_rec_t * agt_cfg_new_auditrec (const xmlChar *target, op_editop_t editop) { agt_cfg_audit_rec_t *auditrec; #ifdef DEBUG if (target == NULL) { SET_ERROR(ERR_INTERNAL_PTR); return NULL; } #endif auditrec = m__getObj(agt_cfg_audit_rec_t); if (!auditrec) { return NULL; } memset(auditrec, 0x0, sizeof(agt_cfg_audit_rec_t)); auditrec->target = xml_strdup(target); if (auditrec->target == NULL) { m__free(auditrec); return NULL; } auditrec->editop = editop; return auditrec; } /* agt_cfg_new_auditrec */
/******************************************************************** * FUNCTION rpc_free_msg * * Free all the memory used by the specified rpc_msg_t * * INPUTS: * msg == rpc_msg_t to clean and delete * RETURNS: * none *********************************************************************/ void rpc_free_msg (rpc_msg_t *msg) { if (!msg) { return; } xml_msg_clean_hdr(&msg->mhdr); //msg->rpc_in_attrs = NULL; //msg->rpc_method = NULL; //msg->rpc_agt_state = 0; /* clean input parameter set */ if (msg->rpc_input) { val_free_value(msg->rpc_input); } //msg->rpc_user1 = NULL; //msg->rpc_user2 = NULL; //msg->rpc_filter.op_filtyp = OP_FILTER_NONE; //msg->rpc_filter.op_filter = NULL; //msg->rpc_datacb = NULL; /* clean data queue */ while (!dlq_empty(&msg->rpc_dataQ)) { val_value_t *val = (val_value_t *)dlq_deque(&msg->rpc_dataQ); val_free_value(val); } m__free(msg); } /* rpc_free_msg */
/******************************************************************** * FUNCTION xml_msg_check_xmlns_attr * * Check the default NS and the prefix map in the msg; * * INPUTS: * msg == message in progress * nsid == namespace ID to check * badns == namespace URI of the bad namespace * used if the nsid is the INVALID marker * attrs == Q to hold the xml_attr_t, if generated * * OUTPUTS: * msg->prefixQ will be populated as needed, * could be partially populated if some error returned * * XMLNS attr entry may be added to the attrs Q * * RETURNS: * status *********************************************************************/ status_t xml_msg_check_xmlns_attr (xml_msg_hdr_t *msg, xmlns_id_t nsid, const xmlChar *badns, xml_attrs_t *attrs) { const xmlChar *pfix; xmlChar *buff; xml_attr_t *attr; status_t res; #ifdef DEBUG if (!msg || !attrs) { return SET_ERROR(ERR_INTERNAL_PTR); } #endif /* no namespace is always ok, and if it is the same as the * current default, then nothing to do */ if (!nsid) { return NO_ERR; } /* not the default, see if prefix already set for this NS */ pfix = find_prefix(msg, nsid); if (pfix) { return NO_ERR; } /* check if this namespace ID already covered because the * xmlns decl is already present in the attrs list parameter */ for (attr = (xml_attr_t *)dlq_firstEntry(attrs); attr != NULL; attr = (xml_attr_t *)dlq_nextEntry(attr)) { if (attr->attr_xmlns_ns == nsid) { return NO_ERR; } } /* not already covered */ buff = NULL; res = xml_msg_gen_new_prefix(msg, nsid, &buff, 0); if (res == NO_ERR) { if (nsid == xmlns_inv_id()) { res = xml_add_inv_xmlns_attr(attrs, nsid, buff, badns); } else { res = xml_add_xmlns_attr(attrs, nsid, buff); } } if (buff) { m__free(buff); } return res; } /* xml_msg_check_xmlns_attr */
/******************************************************************** * FUNCTION cleanup_subsys * * Cleanup the subsystem * *********************************************************************/ static void cleanup_subsys (void) { if (client_addr) { m__free(client_addr); } if (user) { m__free(user); } if (ncxconnect) { close(ncxsock); } if (errfile) { fclose(errfile); } } /* cleanup_subsys */
/******************************************************************** * FUNCTION save_aliases * * Save the aliases to the specified filespec * * INPUT: * fspec == output filespec to use (NULL == default) * * RETURNS: * status *********************************************************************/ status_t save_aliases (const xmlChar *fspec) { if (fspec == NULL) { fspec = get_aliases_file(); } status_t res = NO_ERR; xmlChar *fullspec = ncx_get_source(fspec, &res); if (res != NO_ERR) { log_error("\nError: Expand source '%s' failed (%s)\n", fspec, get_error_string(res)); return res; } res = check_for_saving_def_yangcli_file (ALIASES_FILE, fullspec); if (res != NO_ERR) { m__free(fullspec); return res; } FILE *fp = fopen((const char *)fullspec, "w"); if (fp) { /* this will truncate the file if there are no aliases */ alias_cb_t *alias; for (alias = get_first_alias(); alias != NULL; alias = get_next_alias(alias)) { write_alias(fp, alias); } /* Save mtime of this aliases file */ res = update_def_yangcli_file_mtime (ALIASES_FILE, fullspec); fclose(fp); } else { res = errno_to_status(); log_error("\nError: Open aliases file '%s' failed (%s)\n", fullspec, get_error_string(res)); } m__free(fullspec); return res; } /* save_aliases */
/******************************************************************** * FUNCTION agt_cfg_free_nodeptr * * Free all the memory used by the specified agt_cfg_nodeptr_t * * INPUTS: * nodeptr == agt_cfg_nodeptr_t to clean and delete *********************************************************************/ void agt_cfg_free_nodeptr (agt_cfg_nodeptr_t *nodeptr) { if (!nodeptr) { return; } m__free(nodeptr); } /* agt_cfg_free_nodeptr */
/******************************************************************** * FUNCTION mgr_rpc_free_reply * * Free a mgr_rpc_rpy_t struct * * INPUTS: * rpy == struct to free * * RETURNS: * none *********************************************************************/ void mgr_rpc_free_reply (mgr_rpc_rpy_t *rpy) { #ifdef DEBUG if (!rpy) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (rpy->msg_id) { m__free(rpy->msg_id); } if (rpy->reply) { val_free_value(rpy->reply); } m__free(rpy); } /* mgr_rpc_free_reply */
/******************************************************************** * FUNCTION agt_cfg_free_undorec * * Free all the memory used by the specified agt_cfg_undo_rec_t * * INPUTS: * undo == agt_cfg_undo_rec_t to clean and delete * RETURNS: * none *********************************************************************/ void agt_cfg_free_undorec (agt_cfg_undo_rec_t *undo) { if (!undo) { return; } clean_undorec(undo, FALSE); m__free(undo); } /* agt_cfg_free_undorec */
/******************************************************************** * FUNCTION mgr_rpc_free_request * * Free a mgr_rpc_req_t struct * * INPUTS: * req == struct to free * * RETURNS: * none *********************************************************************/ void mgr_rpc_free_request (mgr_rpc_req_t *req) { #ifdef DEBUG if (!req) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (req->msg_id) { m__free(req->msg_id); } xml_clean_attrs(&req->attrs); if (req->data) { val_free_value(req->data); } m__free(req); } /* mgr_rpc_free_request */
/******************************************************************** * FUNCTION log_vendor_cleanup * * Cleanup vendor related logging state, if any. * * Note: Invocation should be delayed to the LAST POSSIBLE MOMENT. * This is because the various cleanup routines often want to log * errors/warnings/info as well various debugs using standard logging. * *********************************************************************/ void log_vendor_cleanup ( void ) { if (logP) { m__free(logP); logP = NULL; } logfn_vendor_send = NULL; log_clr_vendor_bfr_allocated(); }
/******************************************************************** * FUNCTION ncx_free_iffeature * * Free a malloced ncx_iffeature_t struct * * INPUTS: * iff == struct to free * *********************************************************************/ void ncx_free_iffeature (ncx_iffeature_t *iff) { #ifdef DEBUG if (!iff) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif if (iff->prefix) { m__free(iff->prefix); } if (iff->name) { m__free(iff->name); } m__free(iff); } /* ncx_free_iffeature */
/******************************************************************** * FUNCTION yangapi_free_rcb * * Free a YANGAPI control block * * INPUTS: * rcb == Yuma REST-API control block to free * RETURNS: * none *********************************************************************/ void yangapi_free_rcb (yangapi_cb_t *rcb) { if (rcb == NULL) { return; } while (!dlq_empty(&rcb->paramQ)) { yangapi_param_t *param = (yangapi_param_t *)dlq_deque(&rcb->paramQ); if (param) { yangapi_free_param(param); } } yangapi_clean_keyvalQ(rcb); m__free(rcb->accept); m__free(rcb->request_method); m__free(rcb->request_uri); xpath_free_pcb(rcb->request_xpath); xpath_free_result(rcb->request_xpath_result); xpath_free_pcb(rcb->query_select_xpath); xpath_free_result(rcb->query_select_xpath_result); xpath_free_pcb(rcb->query_test_xpath); xpath_free_result(rcb->query_test_xpath_result); m__free(rcb->content_type); m__free(rcb->content_length); m__free(rcb->if_modified_since); m__free(rcb->if_unmodified_since); m__free(rcb->if_match); m__free(rcb->if_none_match); m__free(rcb); } /* yangapi_free_rcb */
/******************************************************************** * Add an ncid or ncxid to a prefix map. * * \param msg the message in progrss * \param attrs the the top-level attrs list (e;g, rpc_in_attrs) * \param ncid the ncid to add. * \return status *********************************************************************/ status_t xml_msg_add_ncid_to_prefix_map (xml_msg_hdr_t* msg, xml_attrs_t* attrs, xmlns_id_t ncid) { status_t res = NO_ERR; if (!find_prefix(msg, ncid) ) { /* add a prefix an xmlns attr for NETCONF */ xmlChar *buff = NULL; res = xml_msg_gen_new_prefix(msg, ncid, &buff, 0); if (res != NO_ERR) { m__free( buff ); return res; } res = xml_add_xmlns_attr(attrs, ncid, buff); if (res != NO_ERR) { m__free( buff ); return res; } /* create a new prefix map */ xmlns_pmap_t *newpmap = xmlns_new_pmap(0); if (!newpmap) { m__free( buff ); return ERR_INTERNAL_MEM; } newpmap->nm_id = ncid; newpmap->nm_pfix = buff; newpmap->nm_topattr = TRUE; add_pmap(msg, newpmap); } return res; } /* xml_msg_add_ncid_to_prefix_map */
/******************************************************************** * FUNCTION agt_cap_cleanup * * Clean the NETCONF agent capabilities * * INPUTS: * none * RETURNS: * none *********************************************************************/ void agt_cap_cleanup (void) { if (agt_caps) { val_free_value(agt_caps); agt_caps = NULL; } if (my_agt_caps) { cap_clean_caplist(my_agt_caps); m__free(my_agt_caps); my_agt_caps = NULL; } } /* agt_cap_cleanup */