示例#1
0
/********************************************************************
* FUNCTION agt_ses_init
*
* INIT 1:
*   Initialize the session manager module data structures
*
* INPUTS:
*   none
* RETURNS:
*   status
*********************************************************************/
status_t
    agt_ses_init (void)
{

    agt_profile_t   *agt_profile;
    status_t         res;
    uint32           i;

    if (agt_ses_init_done) {
        return ERR_INTERNAL_INIT_SEQ;
    }

#ifdef AGT_STATE_DEBUG
    log_debug2("\nagt: Loading netconf-state module");
#endif

    agt_profile = agt_get_profile();

    for (i=0; i<AGT_SES_MAX_SESSIONS; i++) {
        agtses[i] = NULL;
    }
    next_sesid = 1;
    mysesmod = NULL;

    agttotals = ses_get_total_stats();
    memset(agttotals, 0x0, sizeof(ses_total_stats_t));
    tstamp_datetime(agttotals->startTime);
    (void)time(&last_timeout_check);
    agt_ses_init_done = TRUE;

    /* load the netconf-state module */
    res = ncxmod_load_module(AGT_SES_MODULE, 
                             NULL, 
                             &agt_profile->agt_savedevQ,
                             &mysesmod);
    if (res != NO_ERR) {
        return res;
    }

    /* set up get-my-session RPC operation */
    res = agt_rpc_register_method(AGT_SES_MODULE,
                                  AGT_SES_GET_MY_SESSION,
                                  AGT_RPC_PH_INVOKE,
                                  get_my_session_invoke);
    if (res != NO_ERR) {
        return SET_ERROR(res);
    }

    /* set up set-my-session RPC operation */
    res = agt_rpc_register_method(AGT_SES_MODULE,
                                  AGT_SES_SET_MY_SESSION,
                                  AGT_RPC_PH_INVOKE,
                                  set_my_session_invoke);
    if (res != NO_ERR) {
        return SET_ERROR(res);
    }

    return res;

}  /* agt_ses_init */
示例#2
0
/********************************************************************
* FUNCTION agt_hello_init
*
* Initialize the agt_hello module
* Adds the agt_hello_dispatch function as the handler
* for the NETCONF <hello> top-level element.
*
* INPUTS:
*   none
* RETURNS:
*   NO_ERR if all okay, the minimum spare requests will be malloced
*********************************************************************/
status_t 
    agt_hello_init (void)
{
    status_t  res;

    if (!agt_hello_init_done) {
        res = top_register_node(NC_MODULE, NCX_EL_HELLO, agt_hello_dispatch);
        if (res != NO_ERR) {
            return res;
        }
        mytotals = ses_get_total_stats();
        agt_hello_init_done = TRUE;
    }
    return NO_ERR;

} /* agt_hello_init */
示例#3
0
/********************************************************************
* FUNCTION agt_top_dispatch_msg
* 
* Find the appropriate top node handler and call it
* called by the transport manager (through the session manager)
* when a new message is detected
*
* INPUTS:
*   scb == session control block containing the xmlreader
*          set at the start of an incoming message.
*
* RETURNS:
*  none
*********************************************************************/
void
    agt_top_dispatch_msg (ses_cb_t **ppscb)
{
    ses_total_stats_t  *myagttotals;
    agt_profile_t      *profile;
    xml_node_t          top;
    status_t            res;
    top_handler_t       handler;
    ses_cb_t           *scb = *ppscb;
    
#ifdef DEBUG
    if (!scb) {
        SET_ERROR(ERR_INTERNAL_PTR);
        return;
    }
#endif

    myagttotals = ses_get_total_stats();
    profile = agt_get_profile();

    xml_init_node(&top);

    /* get the first node */
    res = agt_xml_consume_node(scb, 
                               &top, 
                               NCX_LAYER_TRANSPORT, 
                               NULL);
    if (res != NO_ERR) {
        scb->stats.inBadRpcs++;
        myagttotals->stats.inBadRpcs++;
        myagttotals->droppedSessions++;

        if (LOGINFO) {
            log_info("\nagt_top: bad msg for session %d (%s)",
                     scb->sid, 
                     get_error_string(res));
        }

        xml_clean_node(&top);
        agt_ses_free_session(scb);

        /* set the supplied ptr to ptr to scb to NULL so that the 
         * caller of this function knows that it was deallotcated */
        *ppscb=NULL;
        return;
    }

    log_debug3("\nagt_top: got node");
    if (LOGDEBUG4 && scb->state != SES_ST_INIT) {
        xml_dump_node(&top);
    }

    /* check node type and if handler exists, then call it */
    if (top.nodetyp==XML_NT_START || top.nodetyp==XML_NT_EMPTY) {
        /* find the owner, elname tuple in the topQ */
        handler = top_find_handler(top.module, top.elname);
        if (handler) {
            /* call the handler */
            (*handler)(scb, &top);
        } else {
            res = ERR_NCX_DEF_NOT_FOUND;
        }
    } else {
        res = ERR_NCX_WRONG_NODETYP;
    }

    /* check any error trying to invoke the top handler */
    if (res != NO_ERR) {
        scb->stats.inBadRpcs++;
        myagttotals->stats.inBadRpcs++;
        myagttotals->droppedSessions++;
        
        if (LOGINFO) {
            log_info("\nagt_top: bad msg for session %d (%s)",
                     scb->sid, 
                     get_error_string(res));
        }

        agt_ses_free_session(scb);

        /* set the supplied ptr to ptr to scb to NULL so that the 
         * caller of this function knows that it was deallotcated */
        *ppscb=NULL;

    } else if (profile->agt_stream_output &&
               scb->state == SES_ST_SHUTDOWN_REQ) {
        /* session was closed */
        agt_ses_kill_session(scb,
                             scb->killedbysid,
                             scb->termreason);
        /* set the supplied ptr to ptr to scb to NULL so that the 
         * caller of this function knows that it was deallotcated */
        *ppscb=NULL;
    }

    xml_clean_node(&top);

} /* agt_top_dispatch_msg */