Esempio n. 1
0
/********************************************************************
 * FUNCTION find_alias
 * 
 * Find the alias record
 *
 * INPUTS:
 *   name == alias name to find (not assumed to be z-terminated
 *   namelen == length of name string
 * RETURNS:
 *   alias record; NULL if not found
 *********************************************************************/
static alias_cb_t *
    find_alias (const xmlChar *name,
                uint32 namelen)
{
    dlq_hdr_t  *aliasQ = get_aliasQ();
    alias_cb_t *curalias;

    if (aliasQ == NULL) {
        SET_ERROR(ERR_INTERNAL_VAL);
        return NULL;
    }

    for (curalias = (alias_cb_t *)dlq_firstEntry(aliasQ);
         curalias != NULL;
         curalias = (alias_cb_t *)dlq_nextEntry(curalias)) {

        uint32 curlen = xml_strlen(curalias->name);
        int ret = xml_strncmp(curalias->name, name, namelen);

        if (ret == 0) {
            if (curlen == namelen) {
                return curalias;
            }
        } else if (ret > 0) {
            /* already past where this name should be sorted */
            return NULL;
        }
    }

    return NULL;

}  /* find_alias */
Esempio n. 2
0
/********************************************************************
 * build a prefix map using the xmplns directives in a message.
 *
 * \param msg the message in progrss
 * \param attrs the the top-level attrs list (e;g, rpc_in_attrs)
 * \return status
 *********************************************************************/
static status_t build_prefix_map_from_xmlns_directives( xml_msg_hdr_t* msg,
        xml_attrs_t* attrs )
{
    xmlns_id_t invid = xmlns_inv_id();
    xml_attr_t *attr = (xml_attr_t *)xml_first_attr(attrs);

    for ( ; attr;  attr = (xml_attr_t *)xml_next_attr(attr)) {

        /* make sure this is an XMLNS attribute with or wo a prefix */
        if (xml_strncmp(XMLNS, attr->attr_qname, XMLNS_LEN)) {
            continue;
        }

        /* find the namespace associated with the prefix
           note: it is not an error to have extra xmlns decls in the <rpc>elem;
           still need to make sure not to reuse the prefix anyway */
        xmlns_t *nsrec = def_reg_find_ns(attr->attr_val);

        /* check if this attribute has a prefix */
        if (attr->attr_qname == attr->attr_name) {
            /* no prefix in the name so this must be the default namespace */
            if ( !nsrec ) {
                /* the default namespace is not one of ours, so it will not be
                 * used in the reply */
                attr->attr_xmlns_ns = invid;
            } else {
                attr->attr_xmlns_ns = nsrec->ns_id;
            }
            continue;
        }

        /* there is a prefix, so get the prefix len.
         * The entire prefix was saved as the attr_name */
        uint32 plen = xml_strlen(attr->attr_name);

        /* get a new prefix map */
        xmlns_pmap_t *newpmap = xmlns_new_pmap(plen+1);
        if (!newpmap) {
            return ERR_INTERNAL_MEM;
        }

        /* save the prefix and the xmlns ID */
        xml_strncpy(newpmap->nm_pfix, attr->attr_name, plen);
        if ( !nsrec ) {
            newpmap->nm_id = invid;
            attr->attr_xmlns_ns = invid;
        } else {
            newpmap->nm_id = nsrec->ns_id;
            attr->attr_xmlns_ns = nsrec->ns_id;
        }
        newpmap->nm_topattr = TRUE;
        add_pmap(msg, newpmap);
    }

    return NO_ERR;
}
Esempio n. 3
0
/********************************************************************
* FUNCTION find_feature_entry
* 
* Find a feature_entry_t
*
* INPUTS:
*   featstr == feature string parm to use
*   featQ == Q of feature_entry_t to use
*
* RETURNS:
*   pointer to found entry or NULL if not found
*********************************************************************/
static feature_entry_t *
    find_feature_entry (const xmlChar *featstr,
                        dlq_hdr_t  *featQ)
{
    uint32 len = 0;
    boolean splitdone = FALSE;
    status_t res = split_feature_string(featstr, &len);
    if (res == NO_ERR) {
        splitdone = TRUE;
    }

    feature_entry_t  *feature_entry = (feature_entry_t *)dlq_firstEntry(featQ);
    for (; feature_entry != NULL;
         feature_entry = (feature_entry_t *)dlq_nextEntry(feature_entry)) {

        if (splitdone && feature_entry->modname) {
            /* match the module name */
            uint32 len2 = xml_strlen(feature_entry->modname);
            if (len != len2) {
                continue;
            }
            if (xml_strncmp(feature_entry->modname, featstr, len)) {
                continue;
            }
        }

        /* match the feature name */
        if (splitdone) {
            if (xml_strcmp(feature_entry->feature, &featstr[len+1])) {
                continue;
            }
        } else {
            if (xml_strcmp(feature_entry->feature, featstr)) {
                continue;
            }
        }

        return feature_entry;
    }

    return NULL;

}  /* find_feature_entry */
Esempio n. 4
0
/********************************************************************
* FUNCTION xml_msg_clean_defns_attr
*
* Get rid of an xmlns=foo default attribute
*
* INPUTS:
*    attrs == xmlns_attrs_t Q to process
*
* OUTPUTS:
*   *attrs will be cleaned as needed,
*
* RETURNS:
*   status
*********************************************************************/
status_t
xml_msg_clean_defns_attr (xml_attrs_t *attrs)
{
    xml_attr_t  *attr, *nextattr;
    uint32       len, len2;

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

    len = xml_strlen(XMLNS);

    for (attr = (xml_attr_t *)xml_first_attr(attrs);
            attr != NULL;
            attr = nextattr) {


        nextattr = (xml_attr_t *)xml_next_attr(attr);

        len2 = xml_strlen(attr->attr_qname);
        if (len2 >= len) {
            if (!xml_strncmp(attr->attr_qname, XMLNS, len)) {
                if (len == len2) {
                    /* this xmlns=foo is getting toosed so
                     * the netconf NSID can be the default
                     */
                    dlq_remove(attr);
                    xml_free_attr(attr);
                    return NO_ERR;
                } /* else xmlns:foo=bar found */
            }  /* else not xmlns */
        }  /* else not 'xmlns' */
    }

    return NO_ERR;

}  /* xml_msg_clean_defns_attr */