예제 #1
0
/********************************************************************
* FUNCTION mgr_cap_set_caps
*
* Initialize the NETCONF manager capabilities
*
* TEMP !!! JUST SET EVERYTHING, WILL REALLY GET FROM MGR STARTUP
*
* INPUTS:
*    none
* RETURNS:
*    NO_ERR if all goes well
*********************************************************************/
status_t 
    mgr_cap_set_caps (void)
{
    val_value_t *oldcaps, *newcaps;
    cap_list_t *oldmycaps,*newmycaps;
    xmlns_id_t  nc_id;
    status_t  res;

    res = NO_ERR;
    newcaps = NULL;
    nc_id = xmlns_nc_id();
    oldcaps = mgr_caps;
    oldmycaps = my_mgr_caps;

    /* get a new cap_list */
    newmycaps = cap_new_caplist();
    if (!newmycaps) {
        res = ERR_INTERNAL_MEM;
    }

    /* get a new val_value_t cap list for manager <hello> messages */
    if (res == NO_ERR) {
        newcaps = xml_val_new_struct(NCX_EL_CAPABILITIES, nc_id);
        if (!newcaps) {
            res = ERR_INTERNAL_MEM;
        }
    }

    /* add capability for NETCONF version 1.0 support */
    if (res == NO_ERR) {
        res = cap_add_std(newmycaps, CAP_STDID_V1);
        if (res == NO_ERR) {
            res = cap_add_stdval(newcaps, CAP_STDID_V1);
        }
    }

    /* check the return value */
    if (res != NO_ERR) {
        /* toss the new, put back the old */
        cap_free_caplist(newmycaps);
        val_free_value(newcaps);
        my_mgr_caps = oldmycaps;
        mgr_caps = oldcaps;
    } else {
        /* toss the old, install the new */
        if (oldmycaps) {
            cap_free_caplist(oldmycaps);
        }
        if (oldcaps) {
            val_free_value(oldcaps);
        }
        my_mgr_caps = newmycaps;
        mgr_caps = newcaps;
    }   

    return res;

} /* mgr_cap_set_caps */
예제 #2
0
/********************************************************************
* FUNCTION agt_cap_set_caps
*
* Initialize the NETCONF agent capabilities
*
* INPUTS:
*    agttarg == the target of edit-config for this agent
*    agtstart == the type of startup configuration for this agent
*    defstyle == default with-defaults style for the entire agent
*
* RETURNS:
*    NO_ERR if all goes well
*********************************************************************/
status_t 
    agt_cap_set_caps (ncx_agttarg_t  agttarg,
                      ncx_agtstart_t agtstart,
                      const xmlChar *defstyle)
{
    xmlns_id_t nc_id = xmlns_nc_id();
    status_t res = NO_ERR;
    val_value_t *newcaps = NULL;
    val_value_t *oldcaps = agt_caps;
    cap_list_t *oldmycaps = my_agt_caps;
    const agt_profile_t *agt_profile = agt_get_profile();

    /* get a new cap_list */
    cap_list_t *newmycaps = cap_new_caplist();
    if (!newmycaps) {
        res = ERR_INTERNAL_MEM;
    }

    /* get a new val_value_t cap list for agent <hello> messages */
    if (res == NO_ERR) {
        newcaps = xml_val_new_struct(NCX_EL_CAPABILITIES, nc_id);
        if (!newcaps) {
            res = ERR_INTERNAL_MEM;
        }
    }

    /* add capability for NETCONF version 1.0 and/or 1.1 support */
    if (res == NO_ERR) {
        if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) {
            res = cap_add_std(newmycaps, CAP_STDID_V1);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_V1);
            }
        }
        if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) {
            res = cap_add_std(newmycaps, CAP_STDID_V11);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_V11);
            }
        }
    }

    if (res == NO_ERR) {
        /* set the capabilities based on the native target */
        switch (agttarg) {
        case NCX_AGT_TARG_RUNNING:
            res = cap_add_std(newmycaps, CAP_STDID_WRITE_RUNNING);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_WRITE_RUNNING);
            }
            break;
        case NCX_AGT_TARG_CANDIDATE:
            res = cap_add_std(newmycaps, CAP_STDID_CANDIDATE);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_CANDIDATE);
            }

            if (res == NO_ERR) {
                if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) {
                    res = cap_add_std(newmycaps, 
                                      CAP_STDID_CONF_COMMIT);
                    if (res == NO_ERR) {
                        res = cap_add_stdval(newcaps, 
                                             CAP_STDID_CONF_COMMIT);
                    }
                }
                if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) {
                    res = cap_add_std(newmycaps, 
                                      CAP_STDID_CONF_COMMIT11);
                    if (res == NO_ERR) {
                        res = cap_add_stdval(newcaps, 
                                             CAP_STDID_CONF_COMMIT11);
                    }
                }
            }
            break;
        default:
            res = SET_ERROR(ERR_INTERNAL_VAL);
            break;
        }
    }

    if (res == NO_ERR) {
        /* set the rollback-on-error capability */
        res = cap_add_std(newmycaps, CAP_STDID_ROLLBACK_ERR);
        if (res == NO_ERR) {
            res = cap_add_stdval(newcaps, CAP_STDID_ROLLBACK_ERR);
        }
    }

    if (res == NO_ERR) {
        if (agt_profile->agt_usevalidate) {
            /* set the validate capability */
            if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) {
                res = cap_add_std(newmycaps, CAP_STDID_VALIDATE);
                if (res == NO_ERR) {
                    res = cap_add_stdval(newcaps, CAP_STDID_VALIDATE);
                }
            }
            if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) {
                res = cap_add_std(newmycaps, CAP_STDID_VALIDATE11);
                if (res == NO_ERR) {
                    res = cap_add_stdval(newcaps, CAP_STDID_VALIDATE11);
                }
            }
        }
    }

    /* check the startup type for distinct-startup capability */
    if (res == NO_ERR) {
        if (agtstart==NCX_AGT_START_DISTINCT) {
            res = cap_add_std(newmycaps, CAP_STDID_STARTUP);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_STARTUP);
            }
        }
    }

    /* set the url capability */
    if (res == NO_ERR) {
        if (agt_profile->agt_useurl) {
            res = cap_add_url(newmycaps, AGT_URL_SCHEME_LIST);
            if (res == NO_ERR) {
                res = cap_add_urlval(newcaps, AGT_URL_SCHEME_LIST);
            }
        }
    }

    /* set the xpath capability */
    if (res == NO_ERR) {
        res = cap_add_std(newmycaps, CAP_STDID_XPATH);
        if (res == NO_ERR) {
            res = cap_add_stdval(newcaps, CAP_STDID_XPATH);
        }
    }

    /* set the notification capability if enabled */
    if (agt_profile->agt_use_notifications) {
        if (res == NO_ERR) {
            res = cap_add_std(newmycaps, CAP_STDID_NOTIFICATION);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_NOTIFICATION);
            }
        }

        /* set the interleave capability */
        if (res == NO_ERR) {
            res = cap_add_std(newmycaps, CAP_STDID_INTERLEAVE);
            if (res == NO_ERR) {
                res = cap_add_stdval(newcaps, CAP_STDID_INTERLEAVE);
            }
        }
    }

    /* set the partial-lock capability */
    if (res == NO_ERR) {
        res = cap_add_std(newmycaps, CAP_STDID_PARTIAL_LOCK);
        if (res == NO_ERR) {
            res = cap_add_stdval(newcaps, 
                                 CAP_STDID_PARTIAL_LOCK);
        }
    }

    /* set the with-defaults capability */
    if (res == NO_ERR) {
        res = cap_add_withdef(newmycaps, defstyle);
        if (res == NO_ERR) {
            res = cap_add_withdefval(newcaps, defstyle);
        }
    }

    /* check the return value */
    if (res != NO_ERR) {
        /* toss the new, put back the old */
        cap_free_caplist(newmycaps);
        val_free_value(newcaps);
        my_agt_caps = oldmycaps;
        agt_caps = oldcaps;
    } else {
        /* toss the old, install the new */
        if (oldmycaps) {
            cap_free_caplist(oldmycaps);
        }
        if (oldcaps) {
            val_free_value(oldcaps);
        }
        my_agt_caps = newmycaps;
        agt_caps = newcaps;
    }   

    return res;

} /* agt_cap_set_caps */