/******************************************************************** * 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 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_new_msg * * Malloc and initialize a new rpc_msg_t struct * * INPUTS: * none * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ rpc_msg_t * rpc_new_msg (void) { rpc_msg_t *msg; msg = m__getObj(rpc_msg_t); if (!msg) { return NULL; } memset(msg, 0x0, sizeof(rpc_msg_t)); xml_msg_init_hdr(&msg->mhdr); dlq_createSQue(&msg->rpc_dataQ); msg->rpc_input = val_new_value(); if (!msg->rpc_input) { rpc_free_msg(msg); return NULL; } msg->rpc_top_editop = OP_EDITOP_MERGE; return msg; } /* rpc_new_msg */
/******************************************************************** * FUNCTION log_vendor_common * * Generate a log entry destined for vendor specific processing * * INPUTS: * recursive == TRUE means this is a recursive callback from print_backtrace() * level == YumaPro log level * sub_level == YumaPro log sub-level * fstr == format string in printf format * args == any additional arguments for printf * *********************************************************************/ void log_vendor_common (boolean recursive, log_debug_t level, log_debug_t sub_level, const char *fstr, va_list args) { log_debug_app_t app = log_get_debug_app(); if (logP == NULL) { /***** MOVE ME *****/ logP = m__getObj(syslog_msg_desc_t); if (!logP) { LOG_INTERNAL_ERR(Vendor output buffer malloc failure, TBD); return; } log_set_vendor_bfr_allocated(); memset(logP, 0x0, sizeof *logP); //logP->initialized = FALSE; logP->first_time = TRUE; /* Bypass integrity check if first init */ log_util_init_buf(logP); /* First init */ /* * Ideally, the vendor callback function has already have been * set to a vendor supplied function at this point. (If so, the * the following call is a NOP.) However, if vendor code is late * to register, or in the complete absence of actual vendor code * capable of registering, redirect to syslog. This allows * --log-vendor testing without actual vendor code (because * the interface is the same). */ log_vendor_extern_register_send_fn(log_vendor_send_to_syslog); } /* * Call common buffering code: */ log_util_logbuf_common(logP, app, level, sub_level, fstr, args); /* Bail if this was backtrace output */ if (recursive) { return; } /* * If this was a conventional log message, and if backtrace * is configured for vendor, then do the callback. Note that * this becomes a reentrant call, but we protect ourselves * via the early exit above. */ if ((level != LOG_DEBUG_WRITE) || (sub_level != LOG_DEBUG_WRITE)) { if (log_do_backtrace(sub_level, log_get_backtrace_vendor())) { /* Call recursively */ log_print_backtrace(sub_level, &log_vendor_common, &log_vendor_append, &log_vendor_flush, log_get_backtrace_detail(), FRAME_OVERHEAD_CNT, "\n--Backtrace: "); } } } /* log_vendor_common */
/******************************************************************** * FUNCTION ncx_new_feature * * Get a new ncx_feature_t struct * * INPUTS: * none * RETURNS: * pointer to a malloced ncx_feature_t struct, * or NULL if malloc error *********************************************************************/ ncx_feature_t * ncx_new_feature (void) { ncx_feature_t *feature; feature = m__getObj(ncx_feature_t); if (!feature) { return NULL; } memset(feature, 0x0, sizeof(ncx_feature_t)); dlq_createSQue(&feature->iffeatureQ); dlq_createSQue(&feature->appinfoQ); /*** setting feature enabled as the default *** the agent code needs to adjust this *** with agt_enable_feature or *** agt_disable_feature() if needed ***/ feature->enabled = feature_enable_default; feature->code = feature_code_default; return feature; } /* ncx_new_feature */
/******************************************************************** * FUNCTION yangapi_new_param * * Create a new YANGAPI paramater * * INPUTS: * parmname == parameter name * parmnamelen == parameter name string length * parmval == parameter value * parmvallen == parameter value string length * RETURNS: * pointer to initialized param, or NULL if malloc error *********************************************************************/ yangapi_param_t * yangapi_new_param (const xmlChar *parmname, uint32 parmnamelen, const xmlChar *parmval, uint32 parmvallen) { yangapi_param_t *param = m__getObj(yangapi_param_t); if (param) { memset(param, 0x0, sizeof(yangapi_param_t)); if (parmname) { param->name = xml_strndup(parmname, parmnamelen); if (!param->name) { yangapi_free_param(param); return NULL; } if (parmval) { param->value = xml_strndup(parmval, parmvallen); if (!param->value) { yangapi_free_param(param); return NULL; } } } } return param; } /* yangapi_new_param */
/******************************************************************** * FUNCTION new_event_cb * * Malloc and fill in a new event control block * * INPUTS: * modname == module name * event == eventname * cbfn == callback function to use * * RETURNS: * filled in struct or NULL if ERR_INTERNAL_MEM *********************************************************************/ static event_cb_t * new_event_cb (const xmlChar *modname, const xmlChar *event, yangcli_notif_cbfn_t cbfn) { event_cb_t *cb = m__getObj(event_cb_t); if (cb == NULL) { return NULL; } memset(cb, 0x0, sizeof(event_cb_t)); cb->modname = xml_strdup(modname); if (cb->modname == NULL) { free_event_cb(cb); return NULL; } cb->event = xml_strdup(event); if (cb->event == NULL) { free_event_cb(cb); return NULL; } cb->cbfn = cbfn; return cb; } /* new_event_cb */
/******************************************************************** * FUNCTION agt_cfg_new_commit_test * * Malloc a agt_cfg_commit_test_t struct * * RETURNS: * malloced commit test struct or NULL if ERR_INTERNAL_MEM *********************************************************************/ agt_cfg_commit_test_t * agt_cfg_new_commit_test (void) { agt_cfg_commit_test_t *commit_test = m__getObj(agt_cfg_commit_test_t); if (commit_test) { memset(commit_test, 0x0, sizeof(agt_cfg_commit_test_t)); } return commit_test; } /* agt_cfg_new_commit_test */
/******************************************************************** * FUNCTION yangapi_new_rcb * * Create a new YANGAPI control block * * INPUTS: * none * RETURNS: * pointer to initialized RCB, or NULL if malloc error *********************************************************************/ yangapi_cb_t * yangapi_new_rcb (void) { yangapi_cb_t *rcb = m__getObj(yangapi_cb_t); if (rcb) { memset(rcb, 0x0, sizeof(yangapi_cb_t)); dlq_createSQue(&rcb->paramQ); dlq_createSQue(&rcb->keyvalQ); } return rcb; } /* yangapi_new_rcb */
/******************************************************************** * FUNCTION agt_cfg_new_transaction * * Malloc and initialize agt_cfg_transaction_t struct * * INPUTS: * cfgid == config ID to use * edit_type == database edit type * rootcheck == TRUE if root_check needs to be done before commit * during agt_val_apply_write; FALSE if it is done * manually via agt_val_root_check * is_validate == TRUE if this is a <validate> operation * the target data nodes will not be altered * at all during the transaction * FALSE if this is some sort of real edit * res == address of return status * OUTPUTS: * *res == return status * RETURNS: * malloced transaction struct; need to call agt_cfg_free_transaction *********************************************************************/ agt_cfg_transaction_t * agt_cfg_new_transaction (ncx_cfg_t cfgid, agt_cfg_edit_type_t edit_type, boolean rootcheck, boolean is_validate, status_t *res) { assert( edit_type && "edit_type in NONE" ); assert( res && "res is NULL" ); cfg_template_t *cfg = cfg_get_config_id(cfgid); if (cfg == NULL) { *res = ERR_NCX_CFG_NOT_FOUND; return NULL; } if (cfg->cur_txid != 0) { /* a current transaction is already in progress */ *res = ERR_NCX_NO_ACCESS_STATE; return NULL; } agt_cfg_transaction_t *txcb = m__getObj(agt_cfg_transaction_t); if (txcb == NULL) { *res = ERR_INTERNAL_MEM; return NULL; } memset(txcb, 0x0, sizeof(agt_cfg_transaction_t)); dlq_createSQue(&txcb->undoQ); dlq_createSQue(&txcb->auditQ); dlq_createSQue(&txcb->deadnodeQ); txcb->txid = allocate_txid(); txcb->cfg_id = cfgid; txcb->rootcheck = rootcheck; txcb->edit_type = edit_type; txcb->is_validate = is_validate; txcb->apply_res = ERR_NCX_SKIPPED; txcb->commit_res = ERR_NCX_SKIPPED; txcb->rollback_res = ERR_NCX_SKIPPED; agt_profile_t *profile = agt_get_profile(); if (profile->agt_config_state == AGT_CFG_STATE_BAD) { txcb->start_bad = TRUE; } cfg->cur_txid = txcb->txid; *res = NO_ERR; return txcb; } /* agt_cfg_new_transaction */
/******************************************************************** * FUNCTION rpc_err_new_info * * Malloc and init an rpc_err_info_t struct * * RETURNS: * malloced error-info record, or NULL if memory error *********************************************************************/ rpc_err_info_t * rpc_err_new_info (void) { rpc_err_info_t *errinfo; errinfo = m__getObj(rpc_err_info_t); if (!errinfo) { return NULL; } memset(errinfo, 0x0, sizeof(rpc_err_info_t)); return errinfo; } /* rpc_err_new_info */
/******************************************************************** * FUNCTION new_dynlib_cb * * Malloc and init a new dynamic library control block * * RETURNS: * malloced struct or NULL if malloc error *********************************************************************/ static agt_dynlib_cb_t * new_dynlib_cb (void) { agt_dynlib_cb_t *dynlib; dynlib = m__getObj(agt_dynlib_cb_t); if (dynlib == NULL) { return NULL; } memset(dynlib, 0x0, sizeof(agt_dynlib_cb_t)); return dynlib; } /* new_dynlib_cb */
/******************************************************************** * FUNCTION agt_cfg_new_undorec * * Malloc and initialize a new agt_cfg_undo_rec_t struct * * INPUTS: * none * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ agt_cfg_undo_rec_t * agt_cfg_new_undorec (void) { agt_cfg_undo_rec_t *undo; undo = m__getObj(agt_cfg_undo_rec_t); if (!undo) { return NULL; } agt_cfg_init_undorec(undo); return undo; } /* agt_cfg_new_undorec */
/******************************************************************** * FUNCTION ncx_new_iffeature * * Get a new ncx_iffeature_t struct * * INPUTS: * none * RETURNS: * pointer to a malloced ncx_iffeature_t struct, * or NULL if malloc error *********************************************************************/ ncx_iffeature_t * ncx_new_iffeature (void) { ncx_iffeature_t *iff; iff = m__getObj(ncx_iffeature_t); if (!iff) { return NULL; } memset(iff, 0x0, sizeof(ncx_iffeature_t)); return iff; } /* ncx_new_iffeature */
/******************************************************************** * FUNCTION agt_cfg_new_nodeptr * * Malloc and initialize a new agt_cfg_nodeptr_t struct * * INPUTS: * node == node to point at * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ agt_cfg_nodeptr_t * agt_cfg_new_nodeptr (val_value_t *node) { agt_cfg_nodeptr_t *nodeptr; nodeptr = m__getObj(agt_cfg_nodeptr_t); if (!nodeptr) { return NULL; } memset(nodeptr, 0x0, sizeof(agt_cfg_nodeptr_t)); nodeptr->node = node; return nodeptr; } /* agt_cfg_new_nodeptr */
/******************************************************************** * FUNCTION yangapi_new_keyval * * Create a new YANGAPI keyval holder * * INPUTS: * keyval == key valuse string * RETURNS: * pointer to initialized keyval, or NULL if malloc error *********************************************************************/ yangapi_keyval_t * yangapi_new_keyval (const xmlChar *keyval) { yangapi_keyval_t *val = m__getObj(yangapi_keyval_t); if (val) { memset(val, 0x0, sizeof(yangapi_keyval_t)); val->value = xml_strdup(keyval); if (!val->value) { yangapi_free_keyval(val); return NULL; } } return val; } /* yangapi_new_keyval */
/******************************************************************** * FUNCTION rpc_err_new_record * * Malloc and init an rpc_err_rec_t struct * * RETURNS: * malloced error record or NULL if memory error *********************************************************************/ rpc_err_rec_t * rpc_err_new_record (void) { rpc_err_rec_t *err; err = m__getObj(rpc_err_rec_t); if (!err) { if (!staterr_inuse) { err = &staterr; staterr_inuse = TRUE; } else { return NULL; } } rpc_err_init_record(err); return err; } /* rpc_err_new_record */
/******************************************************************** * FUNCTION grp_new_template * * Malloc and initialize the fields in a grp_template_t * * RETURNS: * pointer to the malloced and initialized struct or NULL if an error *********************************************************************/ grp_template_t * grp_new_template (void) { grp_template_t *grp; grp = m__getObj(grp_template_t); if (!grp) { return NULL; } (void)memset(grp, 0x0, sizeof(grp_template_t)); dlq_createSQue(&grp->typedefQ); dlq_createSQue(&grp->groupingQ); dlq_createSQue(&grp->datadefQ); dlq_createSQue(&grp->appinfoQ); grp->status = NCX_STATUS_CURRENT; /* default */ return grp; } /* grp_new_template */
/******************************************************************** * FUNCTION new_reply * * Malloc and initialize a new mgr_rpc_rpy_t struct * * INPUTS: * none * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ static mgr_rpc_rpy_t * new_reply (void) { mgr_rpc_rpy_t *rpy; rpy = m__getObj(mgr_rpc_rpy_t); if (!rpy) { return NULL; } memset(rpy, 0x0, sizeof(mgr_rpc_rpy_t)); rpy->reply = val_new_value(); if (!rpy->reply) { m__free(rpy); return NULL; } /* xml_msg_init_hdr(&rpy->mhdr); */ return rpy; } /* new_reply */
/******************************************************************** * FUNCTION new_msg * * Malloc and initialize a new mgr_not_msg_t struct * * INPUTS: * none * RETURNS: * pointer to struct or NULL or memory error *********************************************************************/ static mgr_not_msg_t * new_msg (void) { mgr_not_msg_t *msg; msg = m__getObj(mgr_not_msg_t); if (!msg) { return NULL; } memset(msg, 0x0, sizeof(mgr_not_msg_t)); msg->notification = val_new_value(); if (!msg->notification) { m__free(msg); return NULL; } /* xml_msg_init_hdr(&msg->mhdr); */ return msg; } /* new_msg */
static agt_cb_queue_notification_set_t* new_callback_set( const xmlChar *modname ) { agt_cb_queue_notification_set_t* cbSet = m__getObj( agt_cb_queue_notification_set_t ); if ( !cbSet ) { return NULL; } memset( cbSet, 0, sizeof( agt_cb_queue_notification_set_t ) ); cbSet->modname = xml_strdup( modname ); if ( !cbSet->modname ) { m__free( cbSet ); return NULL; } return cbSet; }
/******************************************************************** * FUNCTION new_feature_entry * * Create a feature_entry_t * * INPUTS: * featstr == feature string parm to use *********************************************************************/ static feature_entry_t * new_feature_entry (const xmlChar *featstr) { uint32 len = 0; boolean splitdone = FALSE; status_t res = split_feature_string(featstr, &len); if (res == NO_ERR) { splitdone = TRUE; } feature_entry_t *feature_entry = m__getObj(feature_entry_t); if (feature_entry == NULL) { return NULL; } memset(feature_entry, 0x0, sizeof(feature_entry_t)); if (splitdone) { feature_entry->modname = xml_strndup(featstr, len); if (feature_entry->modname == NULL) { free_feature_entry(feature_entry); return NULL; } feature_entry->feature = xml_strdup(&featstr[len+1]); if (feature_entry->feature == NULL) { free_feature_entry(feature_entry); return NULL; } } else { feature_entry->feature = xml_strdup(featstr); if (feature_entry->feature == NULL) { free_feature_entry(feature_entry); return NULL; } } return feature_entry; } /* new_feature_entry */
/******************************************************************** * FUNCTION ncx_clone_iffeature * * Clone a new ncx_iffeature_t struct * * INPUTS: * srciff == ifffeature struct to clone * RETURNS: * pointer to a malloced ncx_iffeature_t struct, * or NULL if malloc error *********************************************************************/ ncx_iffeature_t * ncx_clone_iffeature (ncx_iffeature_t *srciff) { ncx_iffeature_t *iff; iff = m__getObj(ncx_iffeature_t); if (!iff) { return NULL; } memset(iff, 0x0, sizeof(ncx_iffeature_t)); if (srciff->prefix) { iff->prefix = xml_strdup(srciff->prefix); if (iff->prefix == NULL) { ncx_free_iffeature(iff); return NULL; } } if (srciff->name) { iff->name = xml_strdup(srciff->name); if (iff->name == NULL) { ncx_free_iffeature(iff); return NULL; } } iff->feature = srciff->feature; ncx_set_error(&iff->tkerr, srciff->tkerr.mod, srciff->tkerr.linenum, srciff->tkerr.linepos); //iff->seen not set return iff; } /* ncx_clone_iffeature */
/******************************************************************** * FUNCTION new_alias * * Malloc and fill in an alias record * * INPUTS: * name == alias name (not z-terminated) * namelen == length of name string * * RETURNS: * pointer to alias record or NULL if none *********************************************************************/ static alias_cb_t * new_alias (const xmlChar *name, uint32 namelen) { alias_cb_t *alias; if (namelen == 0) { SET_ERROR(ERR_INTERNAL_VAL); return NULL; } alias = m__getObj(alias_cb_t); if (alias == NULL) { return NULL; } memset(alias, 0x0, sizeof(alias_cb_t)); alias->name = xml_strndup(name, namelen); if (alias->name == NULL) { free_alias(alias); return NULL; } return alias; } /* new_alias */
/******************************************************************** * FUNCTION new_feature_entry2 * * Create a feature_entry_t * * INPUTS: * modname == module name to use * name == feature name to use *********************************************************************/ static feature_entry_t * new_feature_entry2 (const xmlChar *modname, const xmlChar *name) { feature_entry_t *feature_entry = m__getObj(feature_entry_t); if (feature_entry == NULL) { return NULL; } memset(feature_entry, 0x0, sizeof(feature_entry_t)); feature_entry->modname = xml_strdup(modname); if (feature_entry->modname == NULL) { free_feature_entry(feature_entry); return NULL; } feature_entry->feature = xml_strdup(name); if (feature_entry->feature == NULL) { free_feature_entry(feature_entry); return NULL; } return feature_entry; } /* new_feature_entry2 */