コード例 #1
0
char* MOF_Object_Reference::to_string() const
{

#ifdef __USE_GNU

    char* buffer = 0;
    size_t buffer_size = 0;
    FILE* stream = open_memstream(&buffer, &buffer_size);
    print(stream);
    fputc('\0', stream);
    fclose(stream);

    return buffer;

#else /* __USE_GNU */

    const char FILE_NAME[] = "memstream.tmp";

    // Write memstream temporary file:

    FILE* stream = fopen(FILE_NAME, "wb");

    if (!stream)
        MOF_error_printf("failed to open %s for write", FILE_NAME);

    print(stream);
    fclose(stream);

    // Reopen file for read:

    stream = fopen(FILE_NAME, "rb");

    if (!stream)
        MOF_error_printf("failed to open %s for read", FILE_NAME);

    size_t n;
    char buffer[4096];
    std::vector<char> v;

    while ((n = fread(buffer, 1, sizeof(buffer), stream)) > 0)
        v.insert(v.end(), buffer, buffer + n);

    v.push_back('\0');
    fclose(stream);

    return strdup(&v[0]);

#endif /* __USE_GNU */
}
コード例 #2
0
void MOF_Object_Reference::validate()
{
    MOF_Class_Decl* class_decl;
    MOF_Key_Value_Pair* p;

    /*
     * Does class exist?
     */

    if ((class_decl = MOF_Class_Decl::find(class_name)) == 0)
    {
        MOF_error_printf("class undefined in reference initializer: \"%s\"",
            class_name);
    }

    /*
     * Validate each key-value pair:
     */

    for (p = pairs; p; p = (MOF_Key_Value_Pair*)p->next)
        p->validate(class_decl);

    /*
     * Check to see that there are as many key-value pairs as keys in the
     * the class.
     */

    if (class_decl->count_keys() != pairs->list_size())
    {
        MOF_error("class contains keys which are missing "
            "from the reference initializer");
    }
}
コード例 #3
0
void MOF_Qualifier::validate_list(int expected_scope)
{
    MOF_Qualifier* p;
    MOF_Qualifier* q;

    /*
     * Check for duplicates:
     */

    for (p = this; p != 0; p = (MOF_Qualifier*)p->next)
    {
        for (q = this; q != p; q = (MOF_Qualifier*)q->next)
        {
            if (strcmp(p->name, q->name) == 0)
                MOF_error_printf("duplicate qualifier: \"%s\"", p->name);
        }
    }

    /*
     * Validate scopes:
     */

    for (p = this; p != 0; p = (MOF_Qualifier*)p->next)
    {
        MOF_Qualifier_Decl* qual_decl;

        /*
         * Find qualifier declaration:
         */

        if ((qual_decl = MOF_Qualifier_Decl::find(p->name)) == 0)
            MOF_error_printf("undefined qualifier \"%s\"", p->name);

        /*
         * Check the scope:
         */

        if (!(qual_decl->scope & expected_scope))
            MOF_error_printf("invalid scope for qualifier \"%s\"", p->name);
    }
}
コード例 #4
0
ファイル: MOF_Buffer.cpp プロジェクト: jubalh/konkretcmpi
void MOF_Buffer::append(const char* data, size_t size)
{
    if (_size + size < _size) {
        // It would overflow, because both size and _size are unsigned
        // and their sum can't be lower than any of them
        MOF_error_printf("Integer overflow detected");
        return;
    }
    reserve(_size + size);
    memcpy(_data + _size, data, size);
    _size += size;
}
コード例 #5
0
static void _check_duplicate_properties(
    MOF_Instance_Decl* inst_decl)
{
    MOF_Property* p;
    MOF_Property* q;
    
    for (p = inst_decl->properties; p; p = (MOF_Property*)p->next)
    {
        for (q = inst_decl->properties; q != p; q = (MOF_Property*)q->next)
        {
            if (MOF_stricmp(p->name, q->name) == 0)
                MOF_error_printf("duplicate property: \"%s\"", p->name);
        }
    }
}
コード例 #6
0
static void _check_undefined_properties(
    const MOF_Class_Decl* class_decl, 
    MOF_Instance_Decl* inst_decl)
{
    MOF_Property* p;

    /* 
     * First check that all instance properties are declared in class
     * and that the types are consistent.
     */

    for (p = inst_decl->properties; p; p = (MOF_Property*)p->next)
    {
        bool found;
        MOF_Feature_Info* q;

        found = false;

        for (q = class_decl->all_features; q; q = (MOF_Feature_Info*)q->next)
        {
            MOF_Feature* feature = q->feature;

            if (MOF_stricmp(p->name, feature->name) == 0)
            {
                MOF_fix_case(p->name, feature->name);

                if (feature->type != MOF_FEATURE_METHOD)
                    found = true;

                break;
            }
        }

        if (!found)
        {
            MOF_error_printf("no such property found in class: \"%s\"",
                p->name);
            return;
        }
    }
}
コード例 #7
0
MOF_Object_Reference* MOF_Instance_Decl::alias_to_obj_ref(const char* alias)
{
    /*
     * Lookup the instance for this alias:
     */

    MOF_Instance_Decl* inst_decl = 
        MOF_Instance_Decl::find_by_alias((char*)alias, false);

    if (!inst_decl)
        MOF_error_printf("undefined alias: \"%s\"", alias);

    /*
     * Create object reference for this instance:
     */

    MOF_Object_Reference* obj_ref = 0;
    _make_obj_ref(inst_decl, obj_ref);
    MOF_ASSERT(obj_ref != 0);

    return obj_ref;
}
コード例 #8
0
char* MOF_Object_Reference::normalize(const char* asc7)
{
    /*
     * Parse the string (to create an obj-ref).
     */

    MOF_Object_Reference* obj_ref;

    if (REF_parse(asc7, &obj_ref) != 0)
    {
        MOF_error_printf(
            "malformed object reference: \"%s\"", ref_error_message);
    }

    /*
     * Validate (causing further parsing of object references).
     */

    obj_ref->validate();

    /*
     * Normalize the obj-ref.
     */

    obj_ref->normalize();

    /*
     * Convert to string.
     */

    char* tmp = obj_ref->to_string();

    delete obj_ref;

    return tmp;
}
コード例 #9
0
void MOF_Instance_Decl::handle(MOF_Instance_Decl* inst_decl)
{
    MOF_Class_Decl* class_decl;

    /*
     * Does class exist?
     */

    if ((class_decl = MOF_Class_Decl::find(
        inst_decl->class_name, true)) == 0)
    {
        MOF_error_printf("instance refers to undefined class: \"%s\"",
            inst_decl->class_name);
    }

    inst_decl->class_decl = class_decl;

    /*
     * Is alias already defined?
     */

    if (inst_decl->alias)
    {
        if (MOF_Class_Decl::find_by_alias(inst_decl->alias) ||
            MOF_Instance_Decl::find_by_alias(inst_decl->alias))
        {
            MOF_error_printf(
                "alias name already defined: \"%s\"", inst_decl->alias);
        }
    }

    /*
     * Build the all qualifiers list:
     */

    inst_decl->all_qualifiers = MOF_Qualifier_Info::make_all_qualifiers(
        class_decl->name, 
        0, 
        0, 
        0,
        inst_decl->qualifiers, 
        class_decl->all_qualifiers,
        &inst_decl->qual_mask,
        false); /* prop */

    /*
     * Check for duplicate features:
     */

    _check_duplicate_properties(inst_decl);

    /*
     * Validate the properties against the class:
     */

    _check_undefined_properties(class_decl, inst_decl);

    /*
     * Build the all-features list:
     */

    _build_all_features_list(class_decl, inst_decl);

    /*
     * Create an instance-name for this instance.
     */

    MOF_Object_Reference* tmp_obj_ref = 0;
    _make_obj_ref(inst_decl, tmp_obj_ref);
    char* inst_name = tmp_obj_ref->to_string();
    delete tmp_obj_ref;

    /*
     * Check that the instance name can be reparsed (sanity check).
     */

    {
        char* tmp = MOF_Object_Reference::normalize(inst_name);
        MOF_ASSERT(strcmp(inst_name, tmp) == 0);
        free(tmp);
    }

    inst_decl->inst_name = inst_name;

    // printf("=== new instance: [%s]\n", inst_name);

    /*
     * See if instance is already defined:
     */

    if (MOF_Instance_Decl::find(inst_name))
    {
        MOF_error_printf("instance already defined: \"%s\"", inst_name);
        return;
    }

    /*
     * Append instance to list:
     */

    if (MOF_Instance_Decl::list)
        MOF_Instance_Decl::list->append(inst_decl);
    else
        MOF_Instance_Decl::list = inst_decl;

#if 0
    _print(inst_decl);
#endif
}
コード例 #10
0
static void _build_all_features_list(
    const MOF_Class_Decl* class_decl, 
    MOF_Instance_Decl* inst_decl)
{
    MOF_Feature_Info* p;
    MOF_Feature_Info* all_features = 0;
    MOF_Property* q;

    /*
     * Iterate the properties in the class and build the all-properties list.
     */

    for (p = class_decl->all_features; p; p = (MOF_Feature_Info*)p->next)
    {
        MOF_Feature* feature = p->feature;
        MOF_Feature_Info* new_feature_info;
        MOF_Property* inst_prop = 0;

        /*
         * First, search for this feature in the instance declaration.
         */

        for (q = inst_decl->properties; q; q = (MOF_Property*)q->next)
        {
            if (MOF_stricmp(feature->name, q->name) == 0)
            {
                inst_prop = q;
                break;
            }
        }

        /*
         * Create a new MOF_Feature_Info object.
         */

        if ((new_feature_info = new MOF_Feature_Info()) == 0)
        {
            MOF_error("out of memory");
            return;
        } 

        /*
         * If instance contains a property with this name:
         */

        if (inst_prop)
        {
            if (feature->type == MOF_FEATURE_PROP)
            {
                MOF_Property_Decl* prop_decl;

                /*
                 * Clone the feature (and initialize).
                 */

                prop_decl = (MOF_Property_Decl*)
                    ((MOF_Property_Decl*)feature)->clone();

                if (prop_decl == 0)
                {
                    MOF_error("out of memory");
                    return;
                }

                prop_decl->qualifiers = inst_prop->qualifiers;
                prop_decl->all_qualifiers = 0;
                prop_decl->qual_mask = 0;
                prop_decl->initializer = inst_prop->initializer;

                /*
                 * Initialize the new_feature_info structure:
                 */

                new_feature_info->feature = (MOF_Feature*)prop_decl;
                new_feature_info->class_origin = p->class_origin;
                new_feature_info->propagated = p->propagated;

                /*
                 * Build the all qualifiers list
                 */

                prop_decl->all_qualifiers = 
                    MOF_Qualifier_Info::make_all_qualifiers(
                        class_decl->name, 
                        0, 
                        inst_prop->name, 
                        0,
                        prop_decl->qualifiers, 
                        feature->all_qualifiers,
                        &prop_decl->qual_mask,
                        true); /* prop */

                /*
                 * Validate the initializer (if any).
                 */

                if (inst_prop->initializer)
                {
                    inst_prop->initializer->validate("property", 
                        inst_prop->name, prop_decl->data_type, 
                        prop_decl->array_index);
                }
            }
            else if (feature->type == MOF_FEATURE_REF)
            {
                MOF_Reference_Decl* ref_decl;

                /*
                 * Clone the feature (and initialize).
                 */

                ref_decl = (MOF_Reference_Decl*)
                    ((MOF_Reference_Decl*)feature)->clone();

                if (ref_decl == 0)
                {
                    MOF_error("out of memory");
                    return;
                }

                ref_decl->qualifiers = inst_prop->qualifiers;
                ref_decl->all_qualifiers = 0;
                ref_decl->qual_mask = 0;
                ref_decl->alias = 0;

                /*
                 * Initialize the new_feature_info structure:
                 */

                new_feature_info->feature = (MOF_Feature*)ref_decl;
                new_feature_info->class_origin = p->class_origin;
                new_feature_info->propagated = p->propagated;

                /*
                 * Build the all qualifiers list
                 */

                ref_decl->all_qualifiers = 
                    MOF_Qualifier_Info::make_all_qualifiers(
                    class_decl->name, 
                    0, 
                    inst_prop->name, 
                    0,
                    ref_decl->qualifiers, 
                    feature->all_qualifiers,
                    &ref_decl->qual_mask,
                    false); /* prop */

                /*
                 * Validate the alias (ATTN) OR object reference.
                 */

                if (inst_prop->initializer)
                {
                    MOF_Object_Reference* obj_ref = 0;

                    /*
                     * Since it's a reference, we expect a string initializer.
                     */

                    if (inst_prop->initializer->value_type != TOK_STRING_VALUE)
                    {
                        MOF_error_printf(
                            "bad ref initializer for property: \"%s\"",
                            inst_prop->name);
                        return;
                    }

                    /*
                     * Parse the object reference string:
                     */

                    if (REF_parse(
                        inst_prop->initializer->string_value, &obj_ref) != 0)
                    {
                        MOF_error_printf(
                            "bad ref initializer for property: \"%s\"",
                            inst_prop->name);
                        return;
                    }

                    /*
                     * Validate and normalize new object reference.
                     */

                    obj_ref->validate();
                    obj_ref->normalize();

                    /*
                     * Be sure the class of the initializer is a sub-class 
                     * of the class of the class's ref decl.
                     */

                    ref_decl->validate_obj_ref(obj_ref);
                    ref_decl->obj_ref = obj_ref;
                }
                else if (inst_prop->alias)
                {
                    MOF_Object_Reference* obj_ref = 
                        MOF_Instance_Decl::alias_to_obj_ref(inst_prop->alias);

                    /*
                     * Be sure the class of the initializer is a sub-class 
                     * of the class of the class's ref decl.
                     */

                    ref_decl->validate_obj_ref(obj_ref);
                    ref_decl->obj_ref = obj_ref;
                }
            }
        }
        else
        {
            /*
             * Propagate feature from class.
             */

            new_feature_info->feature = p->feature;
            new_feature_info->class_origin = p->class_origin;
            new_feature_info->propagated = true;
        }

        /*
         * Append to list:
         */

        if (all_features)
            all_features->append(new_feature_info);
        else
            all_features = new_feature_info;
    }

    inst_decl->all_features = all_features;
}
コード例 #11
0
MOF_Qualifier_Info* MOF_Qualifier_Info::make_all_qualifiers(
    const char* class_name,
    const char* /* inst_name */,
    const char* feature_name,
    const char* param_name,
    MOF_Qualifier* local_qualifiers,
    MOF_Qualifier_Info* inherited_qual_info_list,
    MOF_mask* qual_mask,
    bool prop)
{
    MOF_Qualifier_Info* all_qualifiers_list = 0;
    MOF_Qualifier_Info* qi;
    MOF_Qualifier* q;

    /*
     * Check for illegal qualifier overrides and append local qualifiers to
     * output list.
     */

    for (q = local_qualifiers; q; q = (MOF_Qualifier*)q->next)
    {
        MOF_Qualifier_Info* new_qi;
        MOF_Qualifier_Decl* qual_decl;

        /*
         * Find qualifier declaration for this qualifier:
         */

        if ((qual_decl = MOF_Qualifier_Decl::find(q->name)) == 0)
        {
            /* This cannot happen since it is checked earlier */
            MOF_error_printf("undeclared qualifier: %s", q->name);
        }

        /*
         * Was this qualifier overriden? If so, be sure there was no
         * attempt to change the value:
         */

        qi = _find(inherited_qual_info_list, q->name);

        if (qi &&
            (qi->flavor & MOF_FLAVOR_DISABLEOVERRIDE) &&
            !MOF_Literal::identical(q->params, qi->qualifier->params))
        {
            char context[1024];
            *context = '\0';

            if (class_name)
            {
                strcat(context, class_name);

                if (feature_name)
                {
                    strcat(context, ".");
                    strcat(context, feature_name);

                    if (param_name)
                    {
                        strcat(context, "().");
                        strcat(context, param_name);
                    }
                }
            }

            MOF_error_printf("attempt to override non-overridable qualifier "
                "(%s) on %s",
                q->name, context);
        }

        /*
         * Create qualifier info object and append to list:
         */

        if ((new_qi = new MOF_Qualifier_Info()) == 0)
            MOF_error_printf("out of memory");

        new_qi->qualifier = q;

        /*
         * If overriding, else use declaration:
         */

        if (qi)
            new_qi->flavor = MOF_Flavor::merge(q->flavor, qi->flavor);
        else
            new_qi->flavor = MOF_Flavor::merge(q->flavor, qual_decl->flavor);

        if (all_qualifiers_list == 0)
            all_qualifiers_list = new_qi;
        else
            all_qualifiers_list->append(new_qi);
    }

    /*
     * Propagate inherited qualifiers.
     */

    for (qi = inherited_qual_info_list; qi; qi = (MOF_Qualifier_Info*)qi->next)
    {
        /*
         * Propagate qualifier if necessary (if TOSUBCLASS flavor is present
         * and qualifier not already present locally).
         */

        if ((qi->flavor & MOF_FLAVOR_TOSUBCLASS) &&
            !_find(all_qualifiers_list, qi->qualifier->name))
        {
            MOF_Qualifier_Info* new_qi;

            if ((new_qi = _clone_propagated(qi)) == 0)
                MOF_error_printf("out of memory");

            if (all_qualifiers_list == 0)
                all_qualifiers_list = new_qi;
            else
                all_qualifiers_list->append(new_qi);
        }
    }

    /*
     * Now build the resulting mask of all boolean qualifiers.
     */

    *qual_mask = _make_qual_mask(all_qualifiers_list, prop, param_name != 0);

    return all_qualifiers_list;
}
コード例 #12
0
void MOF_Qualifier::validate()
{
    MOF_Qualifier_Decl* qual_decl;

    /*
     * Find qualifier declaration:
     */

    if ((qual_decl = MOF_Qualifier_Decl::find(name)) == 0)
        MOF_error_printf("undefined qualifier: \"%s\"\n", name);

    /*
     * The presence of a scalar boolean qualifier without arguments implies
     * true.
     */

    if (qual_decl->data_type == TOK_BOOLEAN &&
        qual_decl->array_index == 0 &&
        (params == 0 || params->value_type == TOK_NULL_VALUE))
    {
        params->delete_list();
        params = new MOF_Literal();
        params->value_type = TOK_BOOL_VALUE;
        params->bool_value = true;
    }

    /*
     * Check the qualifier params (if any):
     */

    if (params)
    {
        params->validate("qualifier", name, qual_decl->data_type,
            qual_decl->array_index);
    }

    /*
     * Free descriptions:
     */

#if 0
    /*
     * Release descriptions (to see how much memory they take).
     */

    if (MOF_stricmp(name, "description") == 0)
    {
        if (params && params->u.string_value)
        {
            free (params->u.string_value);
            params->u.string_value = 0;

            free (params);
            params = 0;
        }

        free (name);
        name = (char*)DESCRIPTION;
    }

#endif

}