コード例 #1
0
ファイル: range_request.c プロジェクト: nrh/range
void range_request_warn_type(range_request* rr, const char* type, const char* node)
{
    range* nodes;

    if (!rr->warn_enabled) return;

    if (!rr->warn_type)
        rr->warn_type = set_new(rr->pool, 0);

    /* nodes that generated a particular warning type */
    nodes = set_get_data(rr->warn_type, type);

    if (!nodes) {
        nodes = range_new(rr);
        set_add(rr->warn_type, type, nodes);
    }

    range_add(nodes, node);
}
コード例 #2
0
ファイル: set_utils.c プロジェクト: armando-2011/grace
int set_set_colors(Quark *pset, unsigned int color)
{
    set *p = set_get_data(pset);
    GraceApp *gapp = gapp_from_quark(pset);
    if (!p || !gapp) {
        return RETURN_FAILURE;
    }
    
    if (color < number_of_colors(grace_get_canvas(gapp->grace))) {
        p->line.line.pen.color    = color;
        p->sym.line.pen.color = color;
        p->sym.fillpen.color  = color;
        p->errbar.pen.color  = color;

        quark_dirtystate_set(pset, TRUE);
        return RETURN_SUCCESS;
    } else {
        return RETURN_FAILURE;
    }
}
コード例 #3
0
ファイル: nodescf.c プロジェクト: A1izee/range
range* rangefunc_get_admin(range_request* rr, range** r)
{
    range* ret = range_new(rr);
    if (!validate_range_args(rr, r, 1)) {
        return ret;
    }
    range* n = r[0];
    apr_pool_t* pool = range_request_pool(rr);
    const char** in_nodes = range_get_hostnames(pool, n);

    set* node_admin = set_new(pool, 40000);
    range* admins_r = _expand_cluster(rr, "HOSTS", "KEYS");
    const char** admins = range_get_hostnames(pool, admins_r);
    const char** p_admin = admins;

    while (*p_admin) {
        range* nodes_r = _expand_cluster(rr, "HOSTS", *p_admin);
        const char** nodes = range_get_hostnames(pool, nodes_r);
        const char** p_nodes = nodes;

        while (*p_nodes) {
            set_add(node_admin, *p_nodes, (void*)*p_admin);
            ++p_nodes;
        }
        ++p_admin;
    }

    while (*in_nodes) {
        const char* admin = set_get_data(node_admin, *in_nodes);
        if (!admin) {
            range_request_warn_type(rr, "NO_ADMIN", *in_nodes);
        }
        else {
            range_add(ret, admin);
        }
        in_nodes++;
    }

    return ret;
}
コード例 #4
0
ファイル: utils.c プロジェクト: armando-2011/grace
double set_get_ybase(Quark *pset)
{
    double ybase = 0.0;
    double xmin, xmax, ymin, ymax;
    Quark *gr;
    set *p;
    world w;
    
    if (!pset) {
        return 0.0;
    }
    
    gr = get_parent_graph(pset);
    p = set_get_data(pset);
    graph_get_world(gr, &w);
    
    set_get_minmax(pset, &xmin, &xmax, &ymin, &ymax);

    switch (p->line.baseline_type) {
    case BASELINE_TYPE_0:
        ybase = 0.0;
        break;
    case BASELINE_TYPE_SMIN:
        ybase = ymin;
        break;
    case BASELINE_TYPE_SMAX:
        ybase = ymax;
        break;
    case BASELINE_TYPE_GMIN:
        ybase = w.yg1;
        break;
    case BASELINE_TYPE_GMAX:
        ybase = w.yg2;
        break;
    default:
        errmsg("Wrong type of baseline");
    }
    
    return ybase;
}
コード例 #5
0
ファイル: yamlfile.c プロジェクト: craig5/range
range* rangefunc_get_cluster(range_request* rr, range** r)
{
    range* ret = range_new(rr);
    apr_pool_t* pool = range_request_lr_pool(rr);
    const char** nodes = range_get_hostnames(pool, r[0]);
    const char** p_nodes = nodes;
    set* node_cluster = _get_clusters(rr);
    
    while (*p_nodes) {
        apr_array_header_t* clusters = set_get_data(node_cluster, *p_nodes);
        if (!clusters)
            range_request_warn_type(rr, "NO_CLUSTER", *p_nodes);
        else {
            /* just get one */
            const char* cluster = ((const char**)clusters->elts)[0];
            assert(cluster);
            range_add(ret, cluster);
        }
        ++p_nodes;
    }

    return ret;
}
コード例 #6
0
ファイル: nodescf.c プロジェクト: VertiPub/libcrange
static set* _cluster_keys(range_request* rr, apr_pool_t* pool,
                          const char* cluster, const char* cluster_file)
{
    char line[32768];
    char* p;
    int ovector[30];
    apr_array_header_t* working_range;
    set* sections;
    char* section;
    char* cur_section;
    apr_pool_t* req_pool = range_request_pool(rr);
    int line_no;
    FILE* fp = fopen(cluster_file, "r");

    if (!fp) {
        range_request_warn(rr, "%s: %s not readable", cluster, cluster_file);
        return set_new(pool, 0);
    }

    if (!include_re) {
        const char* error;
        include_re = pcre_compile(INCLUDE_RE, 0, &error, ovector, NULL);
        assert(include_re);

        exclude_re = pcre_compile(EXCLUDE_RE, 0, &error, ovector, NULL);
        assert(exclude_re);
    }

    sections = set_new(pool, 0);
    section = cur_section = NULL;


    working_range = apr_array_make(req_pool, 1, sizeof(char*));
    line_no = 0;
    while (fgets(line, sizeof line, fp)) {
        int len;
        int count;
        line_no++;
        line[sizeof line - 1] = '\0';
        len = strlen(line);
        if (len+1 >= sizeof(line) && line[len - 1] != '\n') {
            /* incomplete line */
            fprintf(stderr, "%s:%d lines > 32767 chars not supported\n", cluster_file, line_no);
            exit(-1);
        }

        line[--len] = '\0'; /* get rid of the \n */
        for (p = line; *p; ++p)
            if (*p == '#') {
                *p = '\0';
                break;
            }

        len = strlen(line);
        if (len == 0) continue;

        for (p = &line[len - 1]; isspace(*p); --p) {
            *p = '\0';
            --len;
        }

        if (!*line) continue;

        if (!(isspace(*line))) {
            cur_section = apr_pstrdup(pool, line);
            continue;
        }

        if (section && strcmp(cur_section, section) != 0) {
            set_add(sections, section, 
                    apr_array_pstrcat(pool, working_range, ','));
            working_range = apr_array_make(req_pool, 1, sizeof(char*));
        }

        section = cur_section;
        count = pcre_exec(include_re, NULL, line, len,
                          0, 0, ovector, 30);
        if (count > 0) {
            line[ovector[3]] = '\0';
            *(char**)apr_array_push(working_range) =
                apr_psprintf(pool, "(%s)",
                             _substitute_dollars(pool, cluster, &line[ovector[2]]));
            continue;
        }

        count = pcre_exec(exclude_re, NULL, line, len,
                          0, 0, ovector, 30);
        if (count > 0) {
            line[ovector[3]] = '\0';
            *(char**)apr_array_push(working_range) =
                apr_psprintf(pool, "-(%s)",
                             _substitute_dollars(pool, cluster, &line[ovector[2]]));
        }

    }
    fclose(fp);

    if (cur_section)
        set_add(sections, cur_section,
                apr_array_pstrcat(pool, working_range, ','));

    set_add(sections, "KEYS", _join_elements(pool, ',', sections));
    set_add(sections, "UP", set_get_data(sections, "CLUSTER"));
    if (set_get(sections, "ALL") && set_get(sections, "CLUSTER"))
        set_add(sections, "DOWN",
                apr_psprintf(pool, "(%s)-(%s)",
                             (char*)set_get_data(sections, "ALL"),
                             (char*)set_get_data(sections, "CLUSTER")));
    return sections;
}
コード例 #7
0
ファイル: nodescf.c プロジェクト: VertiPub/libcrange
static vips* _parse_cluster_vips(range_request* rr, const char* cluster)
{
    struct stat st;
    int ovector[30];
    char line[32768];
    int line_no;
    FILE* fp;
    apr_pool_t* req_pool = range_request_pool(rr);
    apr_pool_t* lr_pool = range_request_lr_pool(rr);
    libcrange* lr = range_request_lr(rr);
    set* cache = libcrange_get_cache(lr, "nodescf:cluster_vips");
    const char* vips_path = apr_psprintf(req_pool, "%s/%s/vips.cf",
                                         nodescf_path, cluster);
    vips* v;
    
    if (!cache) {
        cache = set_new(lr_pool, 0);
        libcrange_set_cache(lr, "nodescf:cluster_vips", cache);
    }

    if (stat(vips_path, &st) == -1) {
        range_request_warn_type(rr, "NOVIPS", cluster);
        return _empty_vips(rr);
    }

    v = set_get_data(cache, vips_path);
    if (!v) {
        v = apr_palloc(lr_pool, sizeof(struct vips));
        apr_pool_create(&v->pool, lr_pool);
        v->vips = set_new(v->pool, 0);
        v->viphosts = set_new(v->pool, 0);
        v->mtime = st.st_mtime;
        set_add(cache, vips_path, v);
    }
    else {
        time_t cached_mtime = v->mtime;
        if (cached_mtime != st.st_mtime) {
            apr_pool_clear(v->pool);
            v->vips = set_new(v->pool, 0);
            v->viphosts = set_new(v->pool, 0);
            v->mtime = st.st_mtime;
        }
        else /* current cached copy is good */
            return v;
    }

    /* create / update the current cached copy */
    fp = fopen(vips_path, "r");
    if (!fp) {
        range_request_warn_type(rr, "NOVIPS", cluster);
        return _empty_vips(rr);
    }

    if (!vips_re) {
        const char* error;
        vips_re = pcre_compile("^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*$", 0, &error,
                               ovector, NULL);
        assert(vips_re);
    }

    line_no = 0;
    while (fgets(line, sizeof line, fp)) {
        int len;
        int count;
        char* p;

        line_no++;
        line[sizeof line - 1] = '\0';
        len = strlen(line);
        if (len+1 >= sizeof(line) && line[len - 1] != '\n') {
            /* incomplete line */
            fprintf(stderr, "%s:%d lines > 32767 chars not supported\n", vips_path, line_no);
            exit(-1);
        }

        line[--len] = '\0'; /* get rid of the \n */
        for (p = line; *p; ++p)
            if (*p == '#') {
                *p = '\0';
                break;
            }

        len = strlen(line);
        if (len == 0) continue;

        for (p = &line[len - 1]; isspace(*p); --p) {
            *p = '\0';
            --len;
        }

        if (!*line) continue;

        /* 68.142.248.161 as301000 eth0:1 */
        count = pcre_exec(vips_re, NULL, line, len, 0, 0, ovector, 30);
        if (count == 4) {
            line[ovector[3]] = '\0';
            line[ovector[5]] = '\0';
            line[ovector[7]] = '\0';

            set_add(v->vips, &line[ovector[2]], 0);
            set_add(v->viphosts, &line[ovector[4]], 0);
        }
    }

    fclose(fp);
    return v;
}
コード例 #8
0
ファイル: libcrange.c プロジェクト: realpdm/libcrange
const char* libcrange_getcfg(libcrange* lr, const char* what)
{
    if (lr == NULL) lr = get_static_lr();

    return set_get_data(lr->vars, what);
}