Beispiel #1
0
rc_t col_defs_unmark_do_not_redact_columns(  col_defs* defs,
                    const char * do_not_redact_cols )
{
    const KNamelist *names;
    rc_t rc;
    
    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( do_not_redact_cols == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &names, do_not_redact_cols );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                if ( col->redactable )
                    if ( nlt_is_name_in_namelist( names, col->name ) )
                        col->redactable = false;
        }
        KNamelistRelease( names );
    }
    return rc;
}
Beispiel #2
0
/*
 * walks through the column-names and marks every column thats
 * name is in "redactable_cols" as redactable
 * sets the redact-value to zero
 * if the default-type of the column is in the list of dna-types
 * (a hardcoded list) it sets the redact-value to 'N'
 * does not require an open cursor. 
*/
rc_t col_defs_detect_redactable_cols_by_name( col_defs* defs,
                                const char * redactable_cols )
{
    const KNamelist *r_columns;
    rc_t rc;
    
    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( defs == NULL || redactable_cols == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &r_columns, redactable_cols );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len && rc == 0; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                if ( !(col->redactable) )
                    col->redactable = nlt_is_name_in_namelist( r_columns, col->name );
        }
        KNamelistRelease( r_columns );
    }
    return rc;
}
Beispiel #3
0
/*
 * walks through the column-definitions and if a column
 * has the to_copy-flag set, and it's name is in the
 * given list of column-names the to copy-flag is cleared
 * does not require an open cursor.
*/
rc_t col_defs_exclude_these_columns( col_defs* defs, const char * prefix, const char * column_names )
{
    rc_t rc = 0;
    const KNamelist *names;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    /* it is OK if we have not column-names to exclude */
    if ( column_names == NULL )
        return 0;
    if ( column_names[0] == 0 )
        return 0;

    rc = nlt_make_namelist_from_string( &names, column_names );
    DISP_RC( rc, "col_defs_parse_string:nlt_make_namelist_from_string() failed" );
    if ( rc == 0 )
    {
        uint32_t idx, len = VectorLength( &(defs->cols) );
        size_t prefix_len = 0;
        if ( prefix != 0 )
            prefix_len = string_size( prefix ) + 2;
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
            {
                if ( col->requested )
                {
                    if ( nlt_is_name_in_namelist( names, col->name ) )
                        col->requested = false;
                    else
                    {
                        if ( prefix != NULL )
                        {
                            size_t len1 = string_size ( col->name ) + prefix_len;
                            char * s = malloc( len1 );
                            if ( s != NULL )
                            {
                                size_t num_writ;
                                rc_t rc1 = string_printf ( s, len1, &num_writ, "%s:%s", prefix, col->name );
                                if ( rc1 == 0 )
                                {
                                    if ( nlt_is_name_in_namelist( names, s ) )
                                        col->requested = false;
                                }
                                free( s );
                            }
                        }
                    }
                }
            }
        }
        KNamelistRelease( names );
    }
    return rc;
}
Beispiel #4
0
rc_t nlt_remove_strings_from_namelist( const KNamelist *source,
                                       const KNamelist **dest, const char *items_to_remove )
{
    rc_t rc = 0;
    const KNamelist *to_remove;

    if ( source == NULL || dest == NULL || items_to_remove == NULL )
        return RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull );
    rc = nlt_make_namelist_from_string( &to_remove, items_to_remove );
    if ( rc == 0 )
    {
        rc = nlt_remove_names_from_namelist( source, dest, to_remove );
        KNamelistRelease( to_remove );
    }
    return rc;
}
Beispiel #5
0
static rc_t matcher_exclude_columns( matcher* self, const char * columns )
{
    const KNamelist *list;
    uint32_t len, idx;
    rc_t rc;

    if ( columns == NULL ) return 0;
    rc = nlt_make_namelist_from_string( &list, columns );
    len = VectorLength( &(self->mcols) );
    for ( idx = 0;  idx < len; ++idx )
    {
        p_mcol col = (p_mcol) VectorGet ( &(self->mcols), idx );
        if ( col != NULL )
            col->excluded = nlt_is_name_in_namelist( list, col->name );
    }
    KNamelistRelease( list );
    return rc;
}
Beispiel #6
0
static rc_t redactable_types_2_type_id_vector( const VSchema * s,
                                               const char * redactable_types,
                                               Vector * id_vector )
{
    const KNamelist *r_types;
    rc_t rc;
    if ( redactable_types == NULL || s == NULL || id_vector == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = nlt_make_namelist_from_string( &r_types, redactable_types );
    if ( rc == 0 )
    {
        uint32_t count, idx;

        rc = KNamelistCount( r_types, &count );
        if ( rc == 0 && count > 0 )
            for ( idx = 0; idx < count && rc == 0; ++idx )
            {
                const char *name;
                rc = KNamelistGet( r_types, idx, &name );
                if ( rc == 0 )
                {
                    VTypedecl td;
                    rc = VSchemaResolveTypedecl ( s, &td, "%s", name );
                    if ( rc == 0 )
                    {
                        uint32_t *id = malloc( sizeof *id );
                        if ( id != NULL )
                        {
                            *id = td.type_id;
                            rc = VectorAppend ( id_vector, NULL, id );
                        }
                        else
                            rc = RC( rcExe, rcNoTarg, rcResolving, rcMemory, rcExhausted );
                    }
                }
            }
        KNamelistRelease( r_types );
    }
    return rc;
}
Beispiel #7
0
rc_t col_defs_mark_requested_columns( col_defs* defs, const char * columns )
{
    const KNamelist *requested;
    rc_t rc;
    uint32_t idx, len;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );

    if ( columns == NULL )
    {
        /* no specific columns are provided --> mark all of them */
        len = VectorLength( &(defs->cols) );
        for ( idx = 0;  idx < len; ++idx )
        {
            p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
            if ( col != NULL )
                col->requested = true;
        }
        rc = 0;
    }
    else
    {
        /* specific columns are provided --> mark all of these */
        rc = nlt_make_namelist_from_string( &requested, columns );
        DISP_RC( rc, "col_defs_mark_requested_columns:nlt_make_namelist_from_string() failed" );
        if ( rc == 0 )
        {
            uint32_t idx, len = VectorLength( &(defs->cols) );
            for ( idx = 0;  idx < len; ++idx )
            {
                p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
                if ( col != NULL )
                    col->requested = nlt_is_name_in_namelist( requested, col->name );
            }
            KNamelistRelease( requested );
        }
    }
    return rc;
}
Beispiel #8
0
static rc_t copy_metadata_root ( const KMDataNode *src_root, KMDataNode *dst_root,
                                 const char * excluded_nodes,
                                 const bool show_meta )
{
    KNamelist *names;
    const KNamelist *excluded_names = NULL;
    uint32_t i, count;

    rc_t rc = KMDataNodeListChild ( src_root, & names );
    DISP_RC( rc, "copy_metadata_root:KMDataNodeListChild() failed" );
    if ( rc != 0 ) return rc;
    
    if ( excluded_nodes != NULL )
    {
        rc = nlt_make_namelist_from_string( &excluded_names, excluded_nodes );
        DISP_RC( rc, "copy_metadata_root:nlt_make_namelist_from_string() failed" );
        if ( rc != 0 ) return rc;
    }

    rc = KNamelistCount ( names, & count );
    for ( i = 0; rc == 0 && i < count; ++ i )
    {
        const char *node_path;
        rc = KNamelistGet ( names, i, & node_path );
        DISP_RC( rc, "copy_metadata_root:KNamelistGet() failed" );
        if ( rc == 0 )
        {
            bool is_excluded = false;
            if ( excluded_names != NULL )
                is_excluded = nlt_is_name_in_namelist( excluded_names, node_path );
            if ( !is_excluded )
                rc = copy_metadata_child ( src_root, dst_root, node_path, show_meta );
        }
    }

    if ( excluded_names != NULL )
        KNamelistRelease( excluded_names );
    KNamelistRelease ( names );
    return rc;
}
Beispiel #9
0
static rc_t matcher_build_column_vector( matcher* self, const char * columns )
{
    const KNamelist *list;
    uint32_t count, idx;
    rc_t rc = nlt_make_namelist_from_string( &list, columns );
    if ( rc != 0 ) return rc;
    rc = KNamelistCount( list, &count );
    if ( rc == 0 )
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char *s;
            rc = KNamelistGet( list, idx, &s );
            if ( rc == 0 )
            {
                p_mcol new_col = matcher_make_col( s );
                if ( new_col == NULL )
                    rc = RC( rcExe, rcNoTarg, rcResolving, rcMemory, rcExhausted );
                if ( rc == 0 )
                    rc = VectorAppend( &(self->mcols), NULL, new_col );
            }
        }
    KNamelistRelease( list );
    return rc;
}