Example #1
0
char* mmg_get_valuef(mmg_conn *db, char *dsn, char *key, int skip, char *qfmt, ...)
{
    HDF *tmpnode; hdf_init(&tmpnode);
    char *val, *querys, sels[256];
    va_list ap;
    NEOERR *err;

    va_start(ap, qfmt);
    querys = vsprintf_alloc(qfmt, ap);
    va_end(ap);
    if (!querys) {
        mtc_err("Unable to allocate mem for query string");
        return NULL;
    }

    snprintf(sels, sizeof(sels), "{'%s': 1}", key);
    err = mmg_prepare(db, MMG_FLAG_EMPTY, skip, 1, NULL, sels, querys);
    RETURN_V_NOK(err, NULL);

    err = mmg_query(db, dsn, NULL, tmpnode);
    RETURN_V_NOK(err, NULL);

    err = hdf_get_copy(tmpnode, key, &val, NULL);
    RETURN_V_NOK(err, NULL);

    hdf_destroy(&tmpnode);
    SAFE_FREE(querys);

    return val;
}
Example #2
0
/*
 * get fileset's info
 * inp: urls, url list you want to get
 * out: files, file list with file_t elements. don't forget free
 */
int file_get_infos_by_list(mdb_conn *conn, ULIST *urls, ULIST **files, int *noksn)
{
    int listlen;
    char *url;
    file_t *file;
    NEOERR *err;
    int ret;

    listlen = uListLength(urls);
    if (listlen <= 0 || urls == NULL || files == NULL) {
        return RET_RBTOP_INPUTE;
    }

    err = uListInit(files, 0, 0);
    RETURN_V_NOK(err, RET_RBTOP_MEMALLOCE);

    int pid = 1;
    int i;
    for (i = 0; i < listlen; i++) {
        err = uListGet(urls, i, (void**)&url);
        RETURN_V_NOK(err, RET_RBTOP_GETLISTE);
        ret = file_get_info_by_id(conn, 0, url, pid, &file);
        if (ret != RET_RBTOP_OK) {
            mtc_warn("can't get file info for %s", url);
            *noksn = i;
            return RET_RBTOP_GETLISTE;
        } else {
            pid = file->id;
            uListAppend(*files, file);
        }
    }
    *noksn = -1;
    return RET_RBTOP_OK;
}
Example #3
0
int mmg_get_int_valuef(mmg_conn *db, char *dsn, char *key, int skip, int limit,
                       char *qfmt, ...)
{
    HDF *tmpnode; hdf_init(&tmpnode);
    char *querys, sels[256];
    int val;
    va_list ap;
    HDF *node;
    NEOERR *err;

    va_start(ap, qfmt);
    querys = vsprintf_alloc(qfmt, ap);
    va_end(ap);
    if (!querys) {
        mtc_err("Unable to allocate mem for query string");
        return 0;
    }

    snprintf(sels, sizeof(sels), "{'%s': 1}", key);
    err = mmg_prepare(db, MMG_FLAG_EMPTY, skip, limit, NULL, sels, querys);
    RETURN_V_NOK(err, 0);

    err = mmg_query(db, dsn, NULL, tmpnode);
    RETURN_V_NOK(err, 0);

    val = 0;
    
    if(hdf_get_valuef(tmpnode, "0.%s", key)) {
        node = hdf_obj_child(tmpnode);
        while (node) {
            val += hdf_get_int_value(node, key, 0);
            
            node = hdf_obj_next(node);
        }
    } else {
        val = hdf_get_int_value(tmpnode, key, 0);
    }

    hdf_destroy(&tmpnode);
    SAFE_FREE(querys);

    return val;
}
Example #4
0
int file_get_infos_by_uri(mdb_conn *conn, char *uri, ULIST **files, int *noksn)
{
    ULIST *urls;
    int listlen;
    NEOERR *err;
    int ret;
    
    err = string_array_split(&urls, uri, URI_SPLITER, MAX_URI_ITEM);
    RETURN_V_NOK(err, RET_RBTOP_INPUTE);
    listlen = uListLength(urls);
    if (listlen < 1) {
        mtc_warn("%s not a valid request", uri);
        return RET_RBTOP_INPUTE;
    }

    ret = file_get_infos_by_list(conn, urls, files, noksn);
    if (urls != NULL)
        uListDestroy(&urls, ULIST_FREE);
    return ret;
}