예제 #1
0
/* Destroy arrays */
void value_destroy_arrays(struct ref_array *raw_lines,
                          struct ref_array *raw_lengths)
{
    TRACE_FLOW_ENTRY();

    /* Function checks validity inside */
    ref_array_destroy(raw_lines);
    /* Function checks validity inside */
    ref_array_destroy(raw_lengths);

    TRACE_FLOW_EXIT();

}
예제 #2
0
/* Create a pair of arrays */
int value_create_arrays(struct ref_array **raw_lines,
                        struct ref_array **raw_lengths)
{
    int error = EOK;
    struct ref_array *new_lines = NULL;
    struct ref_array *new_lengths = NULL;

    TRACE_FLOW_ENTRY();

    error = ref_array_create(&new_lines,
                             sizeof(char *),
                             INI_ARRAY_GROW,
                             value_lines_cleanup_cb,
                             NULL);
    if (error) {
        TRACE_ERROR_NUMBER("Failed to create lines array", error);
        return error;

    }

    error = ref_array_create(&new_lengths,
                             sizeof(uint32_t),
                             INI_ARRAY_GROW,
                             NULL,
                             NULL);
    if (error) {
        TRACE_ERROR_NUMBER("Failed to create lengths array", error);
        ref_array_destroy(new_lines);
        return error;

    }

    *raw_lines = new_lines;
    *raw_lengths = new_lengths;

    TRACE_FLOW_EXIT();
    return EOK;
}
예제 #3
0
/* Copy array */
int ref_array_copy(struct ref_array *ra,
                   ref_array_copy_cb copy_cb,
                   ref_array_fn cb,
                   void *data,
                   struct ref_array **copy_ra)
{
    int error = EOK;
    int idx;
    struct ref_array *new_ra = NULL;
    void *src;
    void *dst;

    TRACE_FLOW_ENTRY();

    /* Check if array is not NULL */
    if ((!ra) || (!copy_ra)) {
        TRACE_ERROR_NUMBER("Invalid argument.", EINVAL);
        return EINVAL;
    }

    new_ra = (struct ref_array *)malloc(sizeof(struct ref_array));
    if (!new_ra) {
        TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM);
        return ENOMEM;
    }

    new_ra->storage = calloc(ra->size, ra->elsize);
    if (!(new_ra->storage)) {
        TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM);
        free(new_ra);
        return ENOMEM;
    }

    new_ra->elsize = ra->elsize;
    new_ra->size = ra->size;
    new_ra->grow_by = ra->grow_by;
    new_ra->len = 0;
    new_ra->refcount = 1;
    new_ra->cb = cb;
    new_ra->cb_data = data;

    for (idx = 0; idx < ra->len; idx++) {
        if (copy_cb) {
            src = (void *)((unsigned char *)(ra->storage) + idx * ra->elsize);
            dst = (void *)((unsigned char *)(new_ra->storage) +
                                             idx * new_ra->elsize);

            error = copy_cb(src, (void *)(dst));
            if (error) {
                TRACE_ERROR_NUMBER("Failed to copy data.", error);
                ref_array_destroy(new_ra);
                return error;
            }
        }
        else {
            memcpy((unsigned char *)(new_ra->storage) + idx * new_ra->elsize,
                   (unsigned char *)(ra->storage) + idx * ra->elsize,
                   new_ra->elsize);
        }
        (new_ra->len)++;
    }


    *copy_ra = new_ra;

    TRACE_FLOW_EXIT();
    return error;
}
예제 #4
0
static int gp_config_from_dir(const char *config_dir,
                              struct gp_ini_context *ctx,
                              struct ini_cfgobj **ini_config,
                              const uint32_t collision_flags)
{
    struct ini_cfgobj *result_cfg = NULL;
    struct ref_array *error_list = NULL;
    int ret;

    const char *patterns[] = {
        /* match only files starting with "##-" and ending in ".conf" */
        "^[0-9]\\{2\\}-.\\{1,\\}\\.conf$",
        NULL,
    };

    const char *sections[] = {
        /* match either "gssproxy" or sections that start with "service/" */
        "^gssproxy$",
        "^service/.*$",
        NULL,
    };

    /* Permission check failures silently skip the file, so they are not
     * useful to us. */
    ret = ini_config_augment(*ini_config,
                             config_dir,
                             patterns,
                             sections,
                             NULL, /* check_perm */
                             INI_STOP_ON_ANY, /* error_level */
                             collision_flags,
                             INI_PARSE_NOWRAP,
                             /* do not allow colliding sections with the same
                              * name in different files */
                             INI_MS_ERROR,
                             &result_cfg,
                             &error_list,
                             NULL);
    if (ret) {
        if (error_list) {
            uint32_t i;
            uint32_t len = ref_array_getlen(error_list, &i);
            for (i = 0; i < len; i++) {
                GPDEBUG("Error when reading config directory: %s\n",
                        (const char *) ref_array_get(error_list, i, NULL));
            }
            ref_array_destroy(error_list);
        } else {
            GPDEBUG("Error when reading config directory number: %d\n", ret);
        }
        return ret;
    }

    /* if we read no new files, result_cfg will be NULL */
    if (result_cfg) {
        ini_config_destroy(*ini_config);
        *ini_config = result_cfg;
    }
    if (error_list) {
        ref_array_destroy(error_list);
    }
    return 0;
}