Esempio n. 1
0
int result2attrset( table_enum table, char **result_tab,
                    unsigned int res_count, attr_set_t * p_set )
{
    int            i;
    unsigned int   nbfields = 0;
    db_type_u      typeu;
    int            mask = 1;

    for ( i = 0; i < ATTR_COUNT; i++, mask <<= 1 )
    {
        if ( ( p_set->attr_mask & mask ) && ( MATCH_TABLE( table, i ) ) )
        {
#ifdef _DEBUG_DB
            DisplayLog( LVL_FULL, LISTMGR_TAG, "result[%u] =  %s", nbfields, result_tab[nbfields] );
#endif

            /* Parse nbfield'th value */
            if ( nbfields >= res_count )
            {
                return DB_BUFFER_TOO_SMALL;
            }

            if ( (result_tab == NULL) || (result_tab[nbfields] == NULL) )
            {
                p_set->attr_mask &= ~( 1 << i );
                nbfields++;
                continue;
            }

            if ( field_infos[i].db_type == DB_STRIPE_INFO )
            {
                if ( result_tab[nbfields] == NULL
                     || result_tab[nbfields+1] == NULL
                     || result_tab[nbfields+2] == NULL )
                {
                    p_set->attr_mask &= ~( 1 << i );
                    nbfields+=3;
                    continue;
                }
                ATTR(p_set, stripe_info).stripe_count = atoi( result_tab[nbfields]  );
                ATTR(p_set, stripe_info).stripe_size = atoi( result_tab[nbfields+1]  );
                strncpy( ATTR(p_set, stripe_info).pool_name, result_tab[nbfields+2] , MAX_POOL_LEN );
                ATTR(p_set, stripe_info).pool_name[MAX_POOL_LEN-1] = 0;

                /* stripe count, stripe size and pool_name */
                nbfields += 3;
                continue;
            }
            else if ( !parsedbtype( result_tab[nbfields], field_infos[i].db_type, &typeu ) )
            {
                DisplayLog( LVL_CRIT, LISTMGR_TAG,
                            "Error: cannot parse field value '%s'", result_tab[nbfields] );
                p_set->attr_mask &= ~( 1 << i );
                nbfields++;
                continue;
            }

            UNION_GET_VALUE( typeu, field_infos[i].db_type,
                             ( ( char * ) &p_set->attr_values + field_infos[i].offset ) );

            nbfields++;
        }
    }
    return 0;

}
Esempio n. 2
0
/**
 * Get next report entry.
 * @param p_value_count is IN/OUT parameter. IN: size of output array. OUT: nbr of fields set in array.
 * @param p_profile OUT: output profile, if required.
 */
int ListMgr_GetNextReportItem(struct lmgr_report_t *p_iter,
                              db_value_t *p_value, unsigned int *p_value_count,
                              profile_u *p_profile)
{
    int rc;
    unsigned int i;

    if (*p_value_count <
        p_iter->result_count - p_iter->profile_count - p_iter->ratio_count)
        return DB_BUFFER_TOO_SMALL;

    if (p_iter->str_tab == NULL) {
        p_iter->str_tab =
            (char **)MemCalloc(p_iter->result_count, sizeof(char *));
        if (!p_iter->str_tab)
            return DB_NO_MEMORY;
    }

    rc = db_next_record(&p_iter->p_mgr->conn, &p_iter->select_result,
                        p_iter->str_tab, p_iter->result_count);

    if (rc)
        return rc;

    /* parse result values */
    for (i = 0;
         i < p_iter->result_count - p_iter->profile_count - p_iter->ratio_count;
         i++) {
        if (p_iter->str_tab[i] != NULL) {
            p_value[i].type = p_iter->result[i].type;
            if (parsedbtype(p_iter->str_tab[i], p_iter->result[i].type,
                            &(p_value[i].value_u)) != 1) {
                DisplayLog(LVL_CRIT, LISTMGR_TAG,
                           "Could not parse result field #%u: value='%s'", i,
                           p_iter->str_tab[i]);
                return DB_INVALID_ARG;
            }
            if (p_iter->result[i].flags & SEPD_LIST)
                separated_db2list_inplace((char *)p_value[i].value_u.val_str);
        } else {
            p_value[i].type = DB_TEXT;
            p_value[i].value_u.val_str = NULL;
        }
    }

    /* fill profile structure */
    if (p_profile && (p_iter->profile_count > 0)) {
        if (p_iter->profile_attr == ATTR_INDEX_size) {
            db_type_u dbval;
            for (i = 0; i < p_iter->profile_count; i++) {
                unsigned int idx = p_iter->result_count - p_iter->profile_count
                    - p_iter->ratio_count + i;
                if (p_iter->str_tab[idx] == NULL) {
                    p_profile->size.file_count[i] = 0;
                } else
                    if (parsedbtype
                        (p_iter->str_tab[idx], p_iter->result[idx].type,
                         &dbval) == 1) {
                    p_profile->size.file_count[i] = dbval.val_biguint;
                } else {
                    DisplayLog(LVL_CRIT, LISTMGR_TAG,
                               "Could not parse result field #%u: value='%s'",
                               idx, p_iter->str_tab[idx]);
                    return DB_INVALID_ARG;
                }
            }
        }
    }

    *p_value_count =
        p_iter->result_count - p_iter->profile_count - p_iter->ratio_count;

    return DB_SUCCESS;
}