Esempio n. 1
0
/********************************************************************
* 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 */
Esempio n. 2
0
/********************************************************************
* FUNCTION mgr_hello_send
*
* Send the manager <hello> message to the server on the 
* specified session
*
* INPUTS:
*   scb == session control block
*
* RETURNS:
*   status
*********************************************************************/
status_t
    mgr_hello_send (ses_cb_t *scb)
{
    val_value_t  *mycaps;
    xml_msg_hdr_t msg;
    status_t      res;
    xml_attrs_t   attrs;
    boolean       anyout;
    xmlns_id_t    nc_id;

#ifdef DEBUG
    if (!scb) {
        return SET_ERROR(ERR_INTERNAL_PTR);
    }
#endif

#ifdef MGR_HELLO_DEBUG
    if (LOGDEBUG2) {
        log_debug2("\nmgr sending hello on session %d", scb->sid);
    }
#endif

    res = NO_ERR;
    anyout = FALSE;
    xml_msg_init_hdr(&msg);
    xml_init_attrs(&attrs);
    nc_id = xmlns_nc_id();

    /* get my client caps, custom made for this session */
    mycaps = mgr_cap_get_ses_capsval(scb);
    if (!mycaps) {
        res = SET_ERROR(ERR_INTERNAL_PTR);
    }

    /* setup the prefix map with the NETCONF namespace */
    if (res == NO_ERR) {
        res = xml_msg_build_prefix_map(&msg, &attrs, TRUE, FALSE);
    }

    /* send the <?xml?> directive */
    if (res == NO_ERR) {
        res = ses_start_msg(scb);
    }

    /* start the hello element */
    if (res == NO_ERR) {
        anyout = TRUE;
        xml_wr_begin_elem_ex(scb, 
                             &msg, 
                             0, 
                             nc_id, 
                             NCX_EL_HELLO, 
                             &attrs, 
                             ATTRQ, 
                             0, 
                             START);
    }
    
    /* send the capabilities list */
    if (res == NO_ERR) {
        xml_wr_full_val(scb, &msg, mycaps, NCX_DEF_INDENT);
    }

    /* finish the hello element */
    if (res == NO_ERR) {
        xml_wr_end_elem(scb, &msg, nc_id, NCX_EL_HELLO, 0);
    }

    /* finish the message */
    if (anyout) {
        ses_finish_msg(scb);
    }

    xml_clean_attrs(&attrs);
    xml_msg_clean_hdr(&msg);
    if (mycaps != NULL) {
        val_free_value(mycaps);
    }
    return res;

} /* mgr_hello_send */
Esempio n. 3
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 */
Esempio n. 4
0
/********************************************************************
* FUNCTION agt_hello_send
*
* Send the server <hello> message to the manager on the 
* specified session
*
* INPUTS:
*   scb == session control block
*
* RETURNS:
*   status
*********************************************************************/
status_t
    agt_hello_send (ses_cb_t *scb)
{
    assert( scb && "scb is NULL!" );
    
    status_t res = NO_ERR;
    boolean anyout = FALSE;
    xmlns_id_t nc_id = xmlns_nc_id();

    xml_msg_hdr_t msg;
    xml_msg_init_hdr(&msg);

    xml_attrs_t attrs;
    xml_init_attrs(&attrs);

    /* start the hello timeout */
    (void)time(&scb->hello_time);

    /* get the server caps */
    val_value_t *mycaps = agt_cap_get_capsval();
    if (!mycaps) {
        res = SET_ERROR(ERR_INTERNAL_PTR);
    }

    /* setup the prefix map with the NETCONF and NCX namepsaces */
    if (res == NO_ERR) {
        res = xml_msg_build_prefix_map(&msg, &attrs, TRUE, FALSE);
    }

    /* send the <?xml?> directive */
    if (res == NO_ERR) {
        res = ses_start_msg(scb);
    }

    boolean mode_started = FALSE;
    if (res == NO_ERR) {
        ses_start_msg_mode(scb);
        mode_started = TRUE;
    }

    int32 msg_indent = ses_message_indent_count(scb);

    /* start the hello element */
    if (res == NO_ERR) {
        anyout = TRUE;
        xml_wr_begin_elem_ex(scb, &msg, 0, nc_id, NCX_EL_HELLO, 
                             &attrs, TRUE, max(msg_indent, 0), FALSE);
    }
    
    /* send the capabilities list */
    if (res == NO_ERR) {
        xml_wr_full_val(scb, &msg, mycaps, msg_indent);
    }

    /* send the session ID */
    if (res == NO_ERR) {
        xml_wr_begin_elem(scb, &msg, nc_id, nc_id, NCX_EL_SESSION_ID, 
                          msg_indent);

    }
    if (res == NO_ERR) {
        xmlChar numbuff[NCX_MAX_NUMLEN];
        snprintf((char *)numbuff, sizeof(numbuff), "%d", scb->sid);
        ses_putstr(scb, numbuff);
    }
    if (res == NO_ERR) {
        xml_wr_end_elem(scb, &msg, nc_id, NCX_EL_SESSION_ID, -1);
    }

    /* finish the hello element */
    if (res == NO_ERR) {
        xml_wr_end_elem(scb, &msg, nc_id, NCX_EL_HELLO, max(msg_indent, 0));
    }

    /* finish the message */
    if (anyout) {
        ses_finish_msg(scb);
    }

    if (mode_started) {
        ses_stop_msg_mode(scb);
    }

    xml_clean_attrs(&attrs);
    xml_msg_clean_hdr(&msg);
    return res;

} /* agt_hello_send */