Ejemplo n.º 1
0
int kp_tget_dec (JSON o, const char **key, bool *dir, bool *link)
{
    json_object_iter iter;
    int rc = -1;
    const char *k = NULL;

    if (!o || !dir || !link || !key) {
        errno = EINVAL;
        goto done;
    }
    json_object_object_foreachC (o, iter) {
        if (!strncmp (iter.key, ".flag_", 6))
            continue;
        if (k) {
            errno = EPROTO;
            goto done;
        }
        k = iter.key;
    }
    if (!k) {
        errno = EPROTO;
        goto done;
    }
    *key = k;
    *dir = false;
    (void)Jget_bool (o, ".flag_directory", dir);
    *link = false;
    (void)Jget_bool (o, ".flag_readlink", link);

    rc = 0;
done:
    return rc;
}
Ejemplo n.º 2
0
static int handle_seq_fetch (seqhash_t *s, JSON in, JSON *outp)
{
    const char *name;
    bool create = false;
    bool created = false;
    int64_t v, pre, post, *valp;

    if (!Jget_str (in, "name", &name)
        || !Jget_bool (in, "create", &create)
        || !Jget_int64 (in, "preincrement", &pre)
        || !Jget_int64 (in, "postincrement", &post)) {
        errno = EPROTO;
        return (-1);
    }
    if (seq_fetch_and_add (s, name, pre, post, &v) < 0) {
        if (!create || (errno != ENOENT))
            return (-1);
        /*  Create and initialize
         */
        valp = seq_create (s, name);
        *valp += pre;
        v = *valp;
        *valp += post;
        created = true;
    }

    *outp = Jnew ();
    Jadd_str (*outp, "name", name);
    Jadd_int64 (*outp, "value", v);
    if (create && created)
        Jadd_bool (*outp, "created", true);
    return (0);
}
Ejemplo n.º 3
0
int kp_twatch_dec (JSON o, const char **key, JSON *val,
                   bool *once, bool *first, bool *dir, bool *link)
{
    json_object_iter iter;
    int rc = -1;
    const char *k = NULL;
    JSON v = NULL;

    if (!o || !key || !val || !once || !first || !dir || !link) {
        errno = EINVAL;
        goto done;
    }
    json_object_object_foreachC (o, iter) {
        if (!strncmp (iter.key, ".flag_", 6))
            continue;
        if (k) {
            errno = EPROTO;
            goto done;
        }
        k = iter.key;
        v = iter.val;
    }
    if (!k) {
        errno = EPROTO;
        goto done;
    }
    *key = k;
    *val = v;
    *once = false;
    (void)Jget_bool (o, ".flag_once", once);
    *first = false;
    (void)Jget_bool (o, ".flag_first", first);
    *dir = false;
    (void)Jget_bool (o, ".flag_directory", dir);
    *link = false;
    (void)Jget_bool (o, ".flag_readlink", link);
    rc = 0;
done:
    return rc;
}
Ejemplo n.º 4
0
resrc_reqst_t *resrc_reqst_from_json (JSON o, resrc_reqst_t *parent)
{
    bool exclusive = false;
    JSON ca = NULL;     /* array of child json objects */
    JSON co = NULL;     /* child json object */
    JSON ga = NULL;     /* array of graph json objects */
    int64_t endtime;
    int64_t qty = 0;
    int64_t size = 0;
    int64_t starttime;
    resrc_reqst_t *child_reqst = NULL;
    resrc_reqst_t *resrc_reqst = NULL;
    resrc_t *resrc = NULL;

    if (!Jget_int64 (o, "req_qty", &qty) && (qty < 1))
        goto ret;

    /*
     * If the size has not been specified, leave it at zero.  A size
     * of zero means that this job request will not consume any part
     * of the resource.  This allows multiple jobs to share the same
     * resource.
     */
    if (Jget_int64 (o, "req_size", &size) && (size < 0))
        goto ret;

    /*
     * If exclusivity has not been specified, leave it at false.
     */
    Jget_bool (o, "exclusive", &exclusive);

    /*
     * We use the request's start time to determine whether to request
     * resources that are available now or in the future.  A zero
     * starttime conveys a request for resources that are available
     * now.
     */
    if (parent)
        starttime = parent->starttime;
    else if (!(Jget_int64 (o, "starttime", &starttime)))
        starttime = 0;

    if (parent)
        endtime = parent->endtime;
    else if (!(Jget_int64 (o, "endtime", &endtime)))
        endtime = TIME_MAX;

    resrc = resrc_new_from_json (o, NULL, false);
    if (resrc) {
        resrc_reqst = resrc_reqst_new (resrc, qty, size, starttime, endtime,
                                       exclusive);

        if ((ga = Jobj_get (o, "graphs")))
            resrc_reqst->g_reqs = resrc_graph_req_from_json (ga);

        if ((co = Jobj_get (o, "req_child"))) {
            child_reqst = resrc_reqst_from_json (co, resrc_reqst);
            if (child_reqst)
                resrc_reqst_add_child (resrc_reqst, child_reqst);
        } else if ((ca = Jobj_get (o, "req_children"))) {
            int i, nchildren = 0;

            if (Jget_ar_len (ca, &nchildren)) {
                for (i=0; i < nchildren; i++) {
                    Jget_ar_obj (ca, i, &co);
                    child_reqst = resrc_reqst_from_json (co, resrc_reqst);
                    if (child_reqst)
                        resrc_reqst_add_child (resrc_reqst, child_reqst);
                }
            }
        }
    }
ret:
    return resrc_reqst;
}