Example #1
0
void* uat_add_record(uat_t* uat, const void* data, gboolean valid_rec) {
    void* rec;
    gboolean* valid;

    /* Save a copy of the raw (possibly that may contain invalid field values) data */
    g_array_append_vals (uat->raw_data, data, 1);

    rec = UAT_INDEX_PTR(uat, uat->raw_data->len - 1);

    if (uat->copy_cb) {
        uat->copy_cb(rec, data, (unsigned int) uat->record_size);
    }

    if (valid_rec) {
        /* Add a "known good" record to the list to be used by the dissector */
        g_array_append_vals (uat->user_data, data, 1);

        rec = UAT_USER_INDEX_PTR(uat, uat->user_data->len - 1);

        if (uat->copy_cb) {
            uat->copy_cb(rec, data, (unsigned int) uat->record_size);
        }

        UAT_UPDATE(uat);
    } else {
        rec = NULL;
    }

    g_array_append_vals (uat->valid_data, &valid_rec, 1);
    valid = &g_array_index(uat->valid_data, gboolean, uat->valid_data->len-1);
    *valid = valid_rec;

    return rec;
}
Example #2
0
void uat_remove_record_idx(uat_t* uat, guint idx) {

    g_assert( idx < uat->user_data->len );

    if (uat->free_cb) {
        uat->free_cb(UAT_INDEX_PTR(uat,idx));
    }

    g_array_remove_index(uat->user_data, idx);

    UAT_UPDATE(uat);

}
Example #3
0
void* uat_add_record(uat_t* uat, const void* data) {
    void* rec;

    g_array_append_vals (uat->user_data, data, 1);

    rec = uat->user_data->data + (uat->record_size * (uat->user_data->len-1));

    if (uat->copy_cb) {
        uat->copy_cb(rec, data, (unsigned int) uat->record_size);
    }

    UAT_UPDATE(uat);

    return rec;
}
Example #4
0
gboolean uat_save(uat_t* uat, char** error) {
    guint i;
    gchar* fname = uat_get_actual_filename(uat,TRUE);
    FILE* fp;

    if (! fname ) return FALSE;

    fp = ws_fopen(fname,"w");

    if (!fp && errno == ENOENT) {
        /* Parent directory does not exist, try creating first */
        gchar *pf_dir_path = NULL;
        if (create_persconffile_dir(&pf_dir_path) != 0) {
            *error = g_strdup_printf("uat_save: error creating '%s'", pf_dir_path);
            g_free (pf_dir_path);
            return FALSE;
        }
        fp = ws_fopen(fname,"w");
    }

    if (!fp) {
        *error = g_strdup_printf("uat_save: error opening '%s': %s",fname,g_strerror(errno));
        return FALSE;
    }

    *error = NULL;
    g_free (fname);

    /* Ensure raw_data is synced with user_data and all "good" entries have been accounted for */

    /* Start by clearing current user_data */
    for ( i = 0 ; i < uat->user_data->len ; i++ ) {
        if (uat->free_cb) {
            uat->free_cb(UAT_USER_INDEX_PTR(uat,i));
        }
    }
    g_array_set_size(uat->user_data,0);

    *((uat)->user_ptr) = NULL;
    *((uat)->nrows_p) = 0;

    /* Now copy "good" raw_data entries to user_data */
    for ( i = 0 ; i < uat->raw_data->len ; i++ ) {
        void *rec = UAT_INDEX_PTR(uat, i);
        gboolean* valid = (gboolean*)(uat->valid_data->data + sizeof(gboolean)*i);
        if (*valid) {
            g_array_append_vals(uat->user_data, rec, 1);
            if (uat->copy_cb) {
                uat->copy_cb(UAT_USER_INDEX_PTR(uat, uat->user_data->len - 1),
                             rec, (unsigned int) uat->record_size);
            }

            UAT_UPDATE(uat);
        }
    }


    fprintf(fp,"# This file is automatically generated, DO NOT MODIFY.\n");

    for ( i = 0 ; i < uat->user_data->len ; i++ ) {
        void* rec = uat->user_data->data + (uat->record_size * i);
        uat_field_t* f;
        guint j;

        f = uat->fields;


        for( j=0 ; j < uat->ncols ; j++ ) {
            putfld(fp, rec, &(f[j]));
            fputs((j == uat->ncols - 1) ? "\n" : "," ,fp);
        }

    }

    fclose(fp);

    uat->changed = FALSE;

    return TRUE;
}