Example #1
0
static int __setPropertyOrigin (struct native_property *prop,
                                const char *name, const char *origin, int mem_state)
{
    if (origin)
    {
        while (prop)
        {
            if (!strcmp(prop->name, name))
            {
                if (prop->origin)
                {
                    if (mem_state == TOOL_MM_NO_ADD)
                    {
                        tool_mm_add (prop->origin);
                    }
                }
                prop->origin = tool_mm_alloc (mem_state, strlen(origin) + 1);
                strcpy (prop->origin, origin);
                return 0;
            }
            prop = prop->next;
        }
    }

    return -1;
}
Example #2
0
static struct native_enum * __new_enumeration ( 
    int mm_add,
    CMPIArray * array,
    CMPIStatus * rc )
{
    static CMPIEnumerationFT eft = {
        NATIVE_FT_VERSION,
        __eft_release,
        __eft_clone,
        __eft_getNext,
        __eft_hasNext,
        __eft_toArray
    };
    static CMPIEnumeration e = {
        "CMPIEnumeration",
        &eft
    };

    struct native_enum * enumeration =
        (struct native_enum *)
    tool_mm_alloc ( mm_add, sizeof ( struct native_enum ) );

    enumeration->enumeration = e;
    enumeration->mem_state   = mm_add;
    enumeration->data =
        ( mm_add == TOOL_MM_NO_ADD )?
        CMClone ( array, rc ): array;

    CMSetStatus ( rc, CMPI_RC_OK );
    return enumeration;
}
Example #3
0
static struct native_context * __new_empty_context ( int mm_add )
{
    static CMPIContextFT cft = {
        NATIVE_FT_VERSION,
        __cft_release,
        __cft_clone,
        __cft_getEntry,
        __cft_getEntryAt,
        __cft_getEntryCount,
        __cft_addEntry
    };
    static CMPIContext c = {
        "CMPIContext",
        &cft
    };

    struct native_context * ctx =
        (struct native_context *)
        tool_mm_alloc ( mm_add, sizeof ( struct native_context ) );

    ctx->ctx       = c;
    ctx->mem_state = mm_add;

    return ctx;
}
Example #4
0
static struct native_string * __new_string (
    int mm_add,
    const char * ptr,
    CMPIStatus * rc )
{
    static CMPIStringFT sft = {
        NATIVE_FT_VERSION,
        __sft_release,
        __sft_clone,
        __sft_getCharPtr
    };

    struct native_string * string =
        (struct native_string *)
    tool_mm_alloc ( mm_add, sizeof ( struct native_string ) );

    string->string.hdl = ( ptr )? strdup ( ptr ): NULL;
    string->string.ft  = &sft;
    string->mem_state  = mm_add;

    if (mm_add == TOOL_MM_ADD)
    {
        tool_mm_add ( string->string.hdl );
    }

    CMSetStatus ( rc, CMPI_RC_OK );
    return string;
}
Example #5
0
static struct native_selectexp * __new_exp ( 
    int mm_add,
    CMPIUint64 id,
    CMPIStatus * rc )
{
    static CMPISelectExpFT eft = {
        NATIVE_FT_VERSION,
        __eft_release,
        __eft_clone,
        __eft_evaluate,
        __eft_getString,
        __eft_getDOC,
        __eft_getCOD,
        __eft_evaluateUsingAccessor
    };
    static CMPISelectExp e = {
        "CMPISelectExp",
        &eft
    };


    struct native_selectexp * exp =
        (struct native_selectexp *)
        tool_mm_alloc ( mm_add, sizeof ( struct native_selectexp ) );

    exp->exp         = e;
    exp->mem_state   = mm_add;
    exp->id          = id;

    CMSetStatus ( rc, CMPI_RC_OK );
    return exp;
}
Example #6
0
static struct native_property * __clone (
    struct native_property * prop,
    CMPIStatus * rc )
{
    struct native_property * result;
    CMPIStatus tmp;

    if (prop == NULL)
    {

        CMSetStatus ( rc, CMPI_RC_OK );
        return NULL;
    }

    result =
        (struct native_property * )
        tool_mm_alloc ( TOOL_MM_NO_ADD,
                        sizeof ( struct native_property ) );

    result->name  = strdup ( prop->name );
    result->origin = prop->origin ? strdup(prop->origin) : 0;
    result->type  = prop->type;
    result->state = prop->state;
    result->value = native_clone_CMPIValue ( prop->type,
                    &prop->value,
                    &tmp );

    if (tmp.rc != CMPI_RC_OK)
    {

        result->state = CMPI_nullValue;
    }

    result->next  = __clone ( prop->next, rc );
    return result;
}
Example #7
0
/**
    returns non-zero if already existant
*/
static int __addProperty (
    struct native_property ** prop,
    int mm_add,
    const char * name,
    CONST CMPIType type,
    CMPIValueState state,
    CONST CMPIValue * value )
{
    CMPIValue v;

    if (*prop == NULL)
    {
        struct native_property * tmp = *prop =
                                           (struct native_property *)
                                           tool_mm_alloc ( mm_add,
                                                   sizeof ( struct native_property ) );

        tmp->name = strdup ( name );

        if (mm_add == TOOL_MM_ADD) tool_mm_add ( tmp->name );

        tmp->type  = type;
        tmp->state = value ? state : CMPI_nullValue;
        if (type == CMPI_chars)
        {

            tmp->type = CMPI_string;
            v.string = native_new_CMPIString ( (char *) value, NULL );
            value = &v;
        }

        if (type != CMPI_null && tmp->state != CMPI_nullValue)
        {

            if (mm_add == TOOL_MM_ADD)
            {

                tmp->value = *value;
            }
            else
            {

                CMPIStatus rc;
                tmp->value = native_clone_CMPIValue ( type, value, &rc );
                // what if clone() fails???
            }
        }
        else
        {
            tmp->state = CMPI_nullValue;
        }

        return 0;
    }
    return( strcmp ( (*prop)->name, name ) == 0 ||
            __addProperty (
                &( (*prop)->next ),
                mm_add,
                name,
                type,
                state,
                value ) );
}