Example #1
0
/********************************************************************
* FUNCTION agt_ses_free_dummy_session
*
* Free a dummy session control block
*
* INPUTS:
*   scb == session control block to free
*
*********************************************************************/
void
    agt_ses_free_dummy_session (ses_cb_t *scb)
{
    assert( scb && "scb is NULL!" );
    assert( agt_ses_init_done && "agt_ses_init_done is false!" );
    assert( agtses[0] && "agtses[0] is null" );

    agt_acm_clear_session_cache(scb);
    ses_free_scb(scb);
    agtses[0] = NULL;

}  /* agt_ses_free_dummy_session */
Example #2
0
/********************************************************************
* FUNCTION agt_ses_free_session
*
* Free a real session control block
*
* INPUTS:
*   scb == session control block to free
*
*********************************************************************/
void
    agt_ses_free_session (ses_cb_t *scb)
{
    ses_id_t  slot;

    assert( scb && "scb is NULL!" );
    assert( agt_ses_init_done && "agt_ses_init_done is false!" );

    if (scb->type==SES_TYP_DUMMY) {
        agt_ses_free_dummy_session( scb );
        return;
    }

    slot = scb->sid;

    if (scb->fd) {
        def_reg_del_scb(scb->fd);
    }

    cfg_release_locks(slot);

    agt_state_remove_session(slot);
    agt_not_remove_subscription(slot);

    /* add this session to ses stats */
    agttotals->active_sessions--;
    if (scb->active) {
        agttotals->closed_sessions++;
    } else {
        agttotals->failed_sessions++;
    }

    /* make sure the ncxserver loop does not try
     * to read from this file descriptor again
     */
    agt_ncxserver_clear_fd(scb->fd);

    /* clear any NACM cache that this session was using */
    agt_acm_clear_session_cache(scb);

    /* this will close the socket if it is still open */
    ses_free_scb(scb);

    agtses[slot] = NULL;

    if (LOGINFO) {
        log_info("\nSession %d closed", slot);
    }

}  /* agt_ses_free_session */
Example #3
0
/********************************************************************
* FUNCTION xml_rd_open_file
* 
* Read the value for the specified obj from an open FILE in XML format
*
* INPUTS:
*    fp == open FILE control block
*    obj == object template for the output value
*    val == address of value for output
*
* RETURNS:
*    status
*********************************************************************/
status_t
    xml_rd_open_file (FILE *fp,
                      obj_template_t *obj, 
                      val_value_t **val)
{
    xml_node_t     top;
    status_t       res;
    /* get a dummy session control block */
    ses_cb_t *scb = ses_new_dummy_scb();
    if (!scb) {
        return ERR_INTERNAL_MEM;
    }
    scb->fp = fp;
    res = xml_get_reader_for_session(my_ses_read_cb,
                                     NULL, scb/*context*/, &scb->reader);
    if(res != NO_ERR) {
        return res;
    }
    /* parse */
    *val = val_new_value();
    if(*val == NULL) {
        return ERR_INTERNAL_MEM;
    }
    xml_init_node(&top);
    
    res = xml_consume_node(scb->reader, &top, TRUE, TRUE);
    if (res != NO_ERR) {
        return res;
    }

    res = val_parse(scb, obj, &top, *val);

    scb->fp = NULL; /* skip fclose inside ses_free_scb */
    ses_free_scb(scb);

    xml_clean_node(&top);

    return res;

} /* xml_rd_open_file */
Example #4
0
/********************************************************************
* FUNCTION json_wr_check_open_file
* 
* Write the specified value to an open FILE in JSON format
*
* INPUTS:
*    fp == open FILE control block
*    val == value for output
*    startindent == starting indent point
*    indent == indent amount (0..9 spaces)
*    testfn == callback test function to use
*
* RETURNS:
*    status
*********************************************************************/
status_t
    json_wr_check_open_file (FILE *fp, 
                             val_value_t *val,
                             int32 startindent,
                             int32  indent,
                             val_nodetest_fn_t testfn)
{
    ses_cb_t   *scb = NULL;
    rpc_msg_t  *msg = NULL;
    status_t    res = NO_ERR;
    xml_attrs_t myattrs;

#ifdef DEBUG
    if (!fp || !val) {
        return SET_ERROR(ERR_INTERNAL_PTR);
    }
#endif

    indent = min(indent, 9);
    xml_init_attrs(&myattrs);

    /* get a dummy session control block */
    scb = ses_new_dummy_scb();
    if (!scb) {
        res = ERR_INTERNAL_MEM;
    } else {
        scb->fp = fp;
        scb->indent = indent;
    }

    /* get a dummy output message */
    if (res == NO_ERR) {
        msg = rpc_new_out_msg();
        if (!msg) {
            res = ERR_INTERNAL_MEM;
        } else {
            /* hack -- need a queue because there is no top
             * element which this usually shadows
             */
            msg->rpc_in_attrs = &myattrs;
        }
    }

    if (res == NO_ERR) {
        /* write the tree in JSON format */
        res = json_wr_full_check_val(scb, &msg->mhdr, val, 
                                     startindent, testfn);
        if (res != ERR_NCX_SKIPPED) {
            ses_finish_msg(scb);
        } else {
            res = NO_ERR;
        }
    }

    /* clean up and exit */
    if (msg) {
        rpc_free_msg(msg);
    }
    if (scb) {
        scb->fp = NULL;   /* do not close the file */
        ses_free_scb(scb);
    }

    xml_clean_attrs(&myattrs);
    return res;

} /* json_wr_check_open_file */