예제 #1
0
static 
rc_t LoadProjects( ProjectTable* data, const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "PROJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, dl_idx, enc_idx;
            rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dl_idx,    "download_ticket" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );
            if (rc == 0 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String download_ticket;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, dl_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&download_ticket, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = KeyRingDataInsertProject(data, id, &name, &download_ticket, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0) 
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
예제 #2
0
static 
rc_t LoadObjects ( ObjectTable* data,  const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "OBJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, proj_idx, dname_idx, size_idx, csum_idx, enc_idx;
            if (rc == 0) rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &proj_idx,    "project" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dname_idx, "display_name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &size_idx,  "size" );
            if (rc == 0) rc = VCursorAddColumn( cur, &csum_idx,  "checksum" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );
            if (rc == 0 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String project;
                            String display_name;
                            uint64_t size;
                            String checksum;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, proj_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&project, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, dname_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&display_name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, size_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) size = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, csum_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&checksum, (const char*)ptr, elem_count, elem_count);

                            if (rc == 0) rc = KeyRingDataInsertObject(data, id, &name, &project, &display_name, size, &checksum, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0)
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
예제 #3
0
static
rc_t copy_row ( const vtblcp_parms *pb, VCursor *dcurs, const VCursor *scurs,
    const vtblcp_column_map *cm, uint32_t count, uint32_t rdfilt_idx, int64_t row )
{
    rc_t rc = VCursorOpenRow ( scurs );
    if ( rc != 0 )
        PLOGERR ( klogErr,  (klogErr, rc, "failed to open source row '$(row)'", "row=%" LD64, row ));
    else
    {
        rc_t rc2;
        rc = VCursorOpenRow ( dcurs );
        if ( rc != 0 )
            PLOGERR ( klogErr,  (klogErr, rc, "failed to open destination row '$(row)'", "row=%" LD64, row ));
        else
        {
            uint32_t i;
            const void *base;
            uint32_t elem_bits, boff, row_len;

            bool redact = false;
            if ( rdfilt_idx != 0 && pb -> redact_sensitive )
            {
                rc = VCursorCellData ( scurs, rdfilt_idx,
                    & elem_bits, & base, & boff, & row_len );
                if ( rc != 0 )
                {
                    PLOGERR ( klogErr,  (klogErr, rc, "failed to read cell data for read filter, row '$(row)'",
                                         "row=%" LD64, row ));
                }
                else
                {
                    const uint8_t *rd_filter = base;
                    for ( i = 0; i < row_len; ++ i )
                    {
                        if ( rd_filter [ i ] == 3 )
                        {
                            redact = pb -> redact_sensitive;
                            break;
                        }
                    }
                }
            }

            for ( i = 0; i < count && rc != 0; ++ i )
            {
                /* get column data */
                rc = VCursorCellData ( scurs, cm [ i ] . rd,
                    & elem_bits, & base, & boff, & row_len );
                if ( rc != 0 )
                {
                    PLOGERR ( klogErr,  (klogErr, rc, "failed to read cell data for column '$(idx)', row '$(row)'",
                                         "idx=%u,row=%" LD64, i, row ));
                    break;
                }

                if ( redact && cm [ i ] . sensitive )
                {
                    uint32_t j;

                    /* substitute base pointer with redact value */
                    base = cm [ i ] . redact_value;

                    /* redact destination */
                    for ( j = 0; j < row_len; ++ j )
                    {
                        rc = VCursorWrite ( dcurs, cm [ i ] . wr, elem_bits, base, 0, 1 );
                        if ( rc != 0 )
                        {
                            PLOGERR ( klogErr,  (klogErr, rc, "failed to redact cell data for column '$(idx)', row '$(row)'",
                                                 "idx=%u,row=%" LD64, i, row ));
                            break;
                        }
                    }
                }
                else
                {
                    /* write to destination */
                    rc = VCursorWrite ( dcurs, cm [ i ] . wr, elem_bits, base, boff, row_len );
                    if ( rc != 0 )
                    {
                        PLOGERR ( klogErr,  (klogErr, rc, "failed to write cell data for column '$(idx)', row '$(row)'",
                                             "idx=%u,row=%" LD64, i, row ));
                        break;
                    }
                }
            }

            /* commit row */
            if ( rc == 0 )
                rc = VCursorCommitRow ( dcurs );

            rc2 = VCursorCloseRow ( dcurs );
            if ( rc == 0 )
                rc = rc2;
        }

        rc2 = VCursorCloseRow ( scurs );
        if ( rc == 0 )
            rc = rc2;
    }

    return rc;
}