Ejemplo n.º 1
0
/********************************************************************
* 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 */
Ejemplo n.º 2
0
/********************************************************************
* 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 */
Ejemplo n.º 3
0
/********************************************************************
* 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 */
Ejemplo n.º 4
0
/********************************************************************
* 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 */
void agt_not_queue_notification_cb_init( void )
{
    if ( !initialised )
    {
        dlq_createSQue( &callbackQ );
        initialised = true;
    }
} /* agt_not_queue_notification_callbacks_init */
Ejemplo n.º 6
0
void agt_commit_complete_init( void )
{
    if ( !initialised )
    {
        dlq_createSQue( &callbackQ );
        initialised = true;
    }
} /* agt_commit_complete_init */
Ejemplo n.º 7
0
/********************************************************************
* 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 */
Ejemplo n.º 8
0
/********************************************************************
 * FUNCTION yangcli_notif_init
 * 
 * Init this module
 *
 *********************************************************************/
void
    yangcli_notif_init (void)
{
    if (!yangcli_notif_init_done) {
        dlq_createSQue(&event_cbQ);
        yangcli_notif_init_done = TRUE;
    } else {
        log_error("\nError: yangcli_notif module already initialized\n");
    }

}  /* yangcli_notif_init */
Ejemplo n.º 9
0
/********************************************************************
* FUNCTION agt_init1
* 
* Initialize the Server Library: stage 1: CLI and profile
* 
* TBD -- put platform-specific server init here
*
* INPUTS:
*   argc == command line argument count
*   argv == array of command line strings
*   showver == address of version return quick-exit status
*   showhelp == address of help return quick-exit status
*
* OUTPUTS:
*   *showver == TRUE if user requsted version quick-exit mode
*   *showhelp == TRUE if user requsted help quick-exit mode
*
* RETURNS:
*   status of the initialization procedure
*********************************************************************/
status_t 
    agt_init1 (int argc,
               char *argv[],
               boolean *showver,
               help_mode_t *showhelpmode)
{
    status_t  res;

    if (agt_init_done) {
        return NO_ERR;
    }

    log_debug3("\nServer Init Starting...");

    res = NO_ERR;

    /* initialize shutdown variables */
    agt_shutdown = FALSE;
    agt_shutdown_started = FALSE;
    agt_shutmode = NCX_SHUT_NONE;
    dlq_createSQue(&agt_dynlibQ);

    *showver = FALSE;
    *showhelpmode = HELP_MODE_NONE;

    /* allow cleanup to run even if this fn does not complete */
    agt_init_done = TRUE;

    init_server_profile();

    /* setup $HOME/.yuma directory */
    res = ncxmod_setup_yumadir();
    if (res != NO_ERR) {
        return res;
    }

    /* get the command line params and also any config file params */
    res = agt_cli_process_input(argc, argv, &agt_profile, showver, 
                                showhelpmode);
    if (res != NO_ERR) {
        return res;
    } /* else the agt_profile is filled in */

    /* check if quick exit mode */
    if (*showver || (*showhelpmode != HELP_MODE_NONE)) {
        return NO_ERR;
    }

    /* loglevel and log file already set */
    return res;

} /* agt_init1 */
Ejemplo n.º 10
0
/********************************************************************
* FUNCTION xml_msg_init_hdr
*
* Initialize a new xml_msg_hdr_t struct
*
* INPUTS:
*   msg == xml_msg_hdr_t memory to initialize
* RETURNS:
*   none
*********************************************************************/
void
xml_msg_init_hdr (xml_msg_hdr_t *msg)
{
    assert(msg && "msg is NULL!");

    memset(msg, 0x0, sizeof(xml_msg_hdr_t));
    dlq_createSQue(&msg->prefixQ);
    dlq_createSQue(&msg->errQ);
    msg->withdef = NCX_DEF_WITHDEF;
    msg->input_encoding = NCX_DEF_ENCODING;
    msg->output_encoding = NCX_DEF_ENCODING;

    if (ncx_get_useprefix()) {
        msg->flags |= XML_MSG_FL_PREFIX;
    }

    msg->msgid = ++next_msgid;
    if (next_msgid == NCX_MAX_UINT32) {
        next_msgid = 0;    // never use msgid zero in a real msg
    }

} /* xml_msg_init_hdr */
Ejemplo n.º 11
0
/********************************************************************
* FUNCTION rpc_err_init_record
*
* Init an rpc_err_rec_t struct
*
* INPUTS:
*   err == rpc_err_rec_t struct to init
* RETURNS:
*   none
*********************************************************************/
void
    rpc_err_init_record (rpc_err_rec_t *err)
{
#ifdef DEBUG
    if (!err) {
        SET_ERROR(ERR_INTERNAL_PTR);
        return;
    }
#endif

    memset(err, 0x0, sizeof(rpc_err_rec_t));
    dlq_createSQue(&err->error_info);

} /* rpc_err_init_record */
Ejemplo n.º 12
0
/********************************************************************
* FUNCTION ncx_feature_init
* 
* Init the ncx_feature module
*
* INPUTS:
*    none
* RETURNS:
*    none
*********************************************************************/
void
    ncx_feature_init (void)
{
    if (feature_init_done) {
        SET_ERROR(ERR_INTERNAL_INIT_SEQ);
        return;
    }

    feature_code_default = NCX_FEATURE_CODE_DYNAMIC;
    feature_enable_default = TRUE;
    dlq_createSQue(&feature_entryQ);
    feature_init_done = TRUE;

}  /* ncx_feature_init */
Ejemplo n.º 13
0
/********************************************************************
* FUNCTION agt_cfg_init_undorec
*
* Initialize a new agt_cfg_undo_rec_t struct
*
* INPUTS:
*   undo == agt_cfg_undo_rec_t memory to initialize
* RETURNS:
*   none
*********************************************************************/
void
    agt_cfg_init_undorec (agt_cfg_undo_rec_t *undo)
{
#ifdef DEBUG
    if (!undo) {
        SET_ERROR(ERR_INTERNAL_PTR);
        return;
    }
#endif

    memset(undo, 0x0, sizeof(agt_cfg_undo_rec_t));
    dlq_createSQue(&undo->extra_deleteQ);
    undo->apply_res = ERR_NCX_SKIPPED;
    undo->commit_res = ERR_NCX_SKIPPED;
    undo->rollback_res = ERR_NCX_SKIPPED;

} /* agt_cfg_init_undorec */
Ejemplo n.º 14
0
/********************************************************************
* FUNCTION init_server_profile
* 
* Hardwire the initial server profile variables
*
* OUTPUTS:
*  *agt_profile is filled in with params of defaults
*
*********************************************************************/
static void
    init_server_profile (void)
{
    memset(&agt_profile, 0x0, sizeof(agt_profile_t));

    /* init server state variables stored here */
    dlq_createSQue(&agt_profile.agt_savedevQ);
    dlq_createSQue(&agt_profile.agt_commit_testQ);
    agt_profile.agt_config_state = AGT_CFG_STATE_INIT;

    /* Set the default values for the user parameters
     * these may be overridden from the command line;
     */
    agt_profile.agt_targ = NCX_AGT_TARG_CANDIDATE;
    agt_profile.agt_start = NCX_AGT_START_MIRROR;
    agt_profile.agt_loglevel = log_get_debug_level();
    agt_profile.agt_log_acm_reads = FALSE;
    agt_profile.agt_log_acm_writes = TRUE;

    /* T: <validate> op on candidate will call all SILs 
     * F: only SILs for nodes changed in the candidate will
     * be called; only affects <validate> command   */
    agt_profile.agt_validate_all = TRUE;

    agt_profile.agt_has_startup = FALSE;
    agt_profile.agt_usestartup = TRUE;
    agt_profile.agt_factorystartup = FALSE;
    agt_profile.agt_startup_error = FALSE;
    agt_profile.agt_running_error = FALSE;
    agt_profile.agt_logappend = FALSE;
    agt_profile.agt_xmlorder = FALSE;
    agt_profile.agt_deleteall_ok = FALSE;
    agt_profile.agt_stream_output = TRUE;

    /* this flag is no longer supported -- it must be
     * set to false for XPath to work correctly
     */
    agt_profile.agt_delete_empty_npcontainers = FALSE;

    /* this flag adds the <sequence-id> leaf to notifications
     * It was default true for yuma through 2.2-3 release
     * Starting 2.2-4 it is removed by default since the XSD
     * in RFC 5277 does not allow extensions
     */
    agt_profile.agt_notif_sequence_id = FALSE;

    agt_profile.agt_accesscontrol = NULL;
    agt_profile.agt_conffile = NULL;
    agt_profile.agt_logfile = NULL;
    agt_profile.agt_startup = NULL;
    agt_profile.agt_defaultStyle = NCX_EL_EXPLICIT;
    agt_profile.agt_superuser = NULL;
    agt_profile.agt_eventlog_size = 1000;
    agt_profile.agt_maxburst = 10;
    agt_profile.agt_hello_timeout = 300;
    agt_profile.agt_idle_timeout = 3600;
    agt_profile.agt_linesize = 72;
    agt_profile.agt_indent = 1;
    agt_profile.agt_usevalidate = TRUE;
    agt_profile.agt_useurl = TRUE;
    agt_profile.agt_defaultStyleEnum = NCX_WITHDEF_EXPLICIT;
    agt_profile.agt_accesscontrol_enum = AGT_ACMOD_ENFORCING;
    agt_profile.agt_system_sorted = AGT_DEF_SYSTEM_SORTED;
    agt_profile.agt_max_sessions = 1024;

} /* init_server_profile */
Ejemplo n.º 15
0
/********************************************************************
* FUNCTION consume_yang_arg
* 
* Parse the next N tokens as an argument-stmt
* Fill in the arg anf argel fields in the ext_template_t struct
*
* Error messages are printed by this function!!
* Do not duplicate error messages upon error return
*
* Current token is the 'argument' keyword
*
* INPUTS:
*   tkc == token chain
*   mod == module in progress
*   ext == extension template in progress
*   argdone == address of duplicate entry error flag
*
* OUTPUTS:
*   *argdone == TRUE upon exit
*
* RETURNS:
*   status of the operation
*********************************************************************/
static status_t 
    consume_yang_arg (tk_chain_t *tkc,
                      ncx_module_t  *mod,
                      ext_template_t *ext,
                      boolean *argdone)
{
    const xmlChar   *val;
    const char      *expstr;
    xmlChar         *errstr;
    dlq_hdr_t        errQ;
    tk_type_t        tktyp;
    boolean          done, yinel, save, errsave;
    status_t         res, retres;

#ifdef DEBUG
    if (!tkc || !mod) {
        return SET_ERROR(ERR_INTERNAL_PTR);
    }
#endif

    val = NULL;
    expstr = NULL;
    done = FALSE;
    yinel = FALSE;
    save = TRUE;
    res = NO_ERR;
    retres = NO_ERR;
    dlq_createSQue(&errQ);

    /* check duplicate entry error first */
    if (*argdone) {
        retres = ERR_NCX_ENTRY_EXISTS;
        ncx_print_errormsg(tkc, mod, retres);
        save = FALSE;
    } else {
        *argdone = TRUE;
    }

    /* Get the mandatory argument name */
    if (save) {
        res = yang_consume_id_string(tkc, mod, &ext->arg);
    } else {
        errstr = NULL;
        res = yang_consume_id_string(tkc, mod, &errstr);
        if (errstr) {
            m__free(errstr);
        }
    }
    CHK_EXIT(res, retres);

    /* Get the starting left brace for the sub-clauses
     * or a semi-colon to end the extension-stmt
     */
    res = TK_ADV(tkc);
    if (res != NO_ERR) {
        ncx_print_errormsg(tkc, mod, res);
        return res;
    }
    switch (TK_CUR_TYP(tkc)) {
    case TK_TT_SEMICOL:
        done = TRUE;
        break;
    case TK_TT_LBRACE:
        break;
    default:
        retres = ERR_NCX_WRONG_TKTYPE;
        expstr = "semi-colon or left brace";
        ncx_mod_exp_err(tkc, mod, retres, expstr);
        done = TRUE;
    }

    /* get the extension statements and any appinfo extensions */
    while (!done) {
        /* get the next token */
        res = TK_ADV(tkc);
        if (res != NO_ERR) {
            ncx_print_errormsg(tkc, mod, res);
            return res;
        }

        tktyp = TK_CUR_TYP(tkc);
        val = TK_CUR_VAL(tkc);

        /* check the current token type */
        switch (tktyp) {
        case TK_TT_NONE:
            res = ERR_NCX_EOF;
            ncx_print_errormsg(tkc, mod, res);
            return res;
        case TK_TT_MSTRING:
            /* vendor-specific clause found instead */
            if (save) {
                res = ncx_consume_appinfo(tkc, mod, &ext->appinfoQ);
            } else {
                res = ncx_consume_appinfo(tkc, mod, &errQ);
                ncx_clean_appinfoQ(&errQ);
            }
            CHK_EXIT(res, retres);
            continue;
        case TK_TT_RBRACE:
            done = TRUE;
            continue;
        case TK_TT_TSTRING:
            break;  /* YANG clause assumed */
        default:
            retres = ERR_NCX_WRONG_TKTYPE;
            ncx_mod_exp_err(tkc, mod, retres, expstr);
            continue;
        }

        /* Got a token string so check the value */
        if (!xml_strcmp(val, YANG_K_YIN_ELEMENT)) {
            if (save) {
                res = yang_consume_boolean(tkc, 
                                           mod, 
                                           &ext->argel,
                                           &yinel, 
                                           &ext->appinfoQ);
            } else {
                res = yang_consume_boolean(tkc, 
                                           mod, 
                                           &errsave,
                                           NULL, 
                                           NULL);
            }
        } else {
            res = ERR_NCX_WRONG_TKVAL;
            ncx_mod_exp_err(tkc, mod, res, expstr);
        }
        CHK_EXIT(res, retres);
    }

    return retres;

}  /* consume_yang_arg */