Example #1
0
static NEOERR* aux_cmd_cmtadd(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    int type, oid, pid;
    char *ip, *addr, *author, *content;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "ip", ip);
    REQ_GET_PARAM_STR(q->hdfrcv, "addr", addr);
    REQ_GET_PARAM_STR(q->hdfrcv, "author", author);
    REQ_GET_PARAM_STR(q->hdfrcv, "content", content);

    REQ_GET_PARAM_INT(q->hdfrcv, "type", type);
    REQ_GET_PARAM_INT(q->hdfrcv, "oid", oid);
    REQ_FETCH_PARAM_INT(q->hdfrcv, "pid", pid);

    MDB_EXEC(db, NULL, "INSERT INTO comment "
             " (type, oid, pid, ip, addr, author, content) "
             " VALUES ($1, $2, $3, $4::varchar(256), "
             " $5::varchar(256), $6::varchar(256), $7)",
             "iiissss", type, oid, pid, ip, addr, author, content);
    
    cache_delf(cd, PREFIX_CMTAPP"%d:%d_0", type, oid);
    
    return STATUS_OK;
}
Example #2
0
static NEOERR* dyn_cmd_getadmin(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    char *uname, *aname;
    int uid, aid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    uid = hash_string(uname);
    aid = hash_string(aname);

    if (cache_getf(cd, &val, &vsize, PREFIX_ADMIN"%d_%d", uid, aid)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        MDB_QUERY_RAW(db, "track", TRACK_COL, "uid=%d AND aid=%d AND type=%d "
                      " ORDER BY id DESC LIMIT 1;",
                      NULL, uid, aid, TYPE_JOIN);
        err = mdb_set_row(q->hdfsnd, db, TRACK_COL, NULL);
        nerr_handle(&err, NERR_NOT_FOUND);
        if (err != STATUS_OK) return nerr_pass(err);

        CACHE_HDF(q->hdfsnd, ONE_MINUTE, PREFIX_ADMIN"%d_%d", uid, aid);
    }
    
    return STATUS_OK;
}
Example #3
0
/*
 * input : pname(STR) aname(STR)
 * return: NORMAL
 * reply : NULL
 */
static NEOERR* aic_cmd_app_setsecy(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *pname, *aname;
    int pid, aid, upid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "pname", pname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);

    pid = hash_string(pname);
    aid = hash_string(aname);

    MDB_EXEC(db, NULL, "UPDATE appinfo SET tune=tune & %d WHERE aid=%d OR pid=%d "
             " RETURNING aid", NULL, ~LCS_TUNE_SECY, pid, pid);

    upid = aid;
    err = mdb_get(db, "i", &upid);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "UPDATE appinfo SET tune=tune | %d WHERE aid=%d",
             NULL, LCS_TUNE_SECY, aid);

    cache_delf(cd, PREFIX_APPINFO"%d", upid);
    cache_delf(cd, PREFIX_APPINFO"%d", aid);
    cache_delf(cd, PREFIX_APPOUSER"%d_0", pid);
    cache_delf(cd, PREFIX_SECY"%d", pid);

    return STATUS_OK;
}
Example #4
0
/*
 * input : uname(STR) aname(STR)
 * return: NORMAL
 * reply : NULL
 */
static NEOERR* aic_cmd_appuserin(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    char *aname, *uname;
    int aid, uid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    aid = hash_string(aname);
    uid = hash_string(uname);

    hdf_set_int_value(q->hdfrcv, "uid", uid);
    hdf_set_int_value(q->hdfrcv, "aid", aid);

    err = aic_cmd_appusers(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname))
        return STATUS_OK;

    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.userinfo"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(db, NULL, "INSERT INTO userinfo %s", NULL, str.buf);
    string_clear(&str);
    
    cache_delf(cd, PREFIX_USERLIST"%d", aid);

    return STATUS_OK;
}
Example #5
0
static NEOERR* dyn_cmd_addtrack(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    char *aname, *uname, *oname;
    int aid, uid, oid = 0;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_FETCH_PARAM_STR(q->hdfrcv, "oname", oname);
    uid = hash_string(uname);
    aid = hash_string(aname);
    if (oname) oid = hash_string(oname);

    hdf_set_int_value(q->hdfrcv, "aid", aid);
    hdf_set_int_value(q->hdfrcv, "uid", uid);
    hdf_set_int_value(q->hdfrcv, "oid", oid);
    
    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.track"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO track %s", NULL, str.buf);
    string_clear(&str);

    return STATUS_OK;
}
Example #6
0
static NEOERR* place_cmd_get(struct city_entry *e, QueueEntry *q)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int count = 0;
    char *ip, tok[64];
    
    REQ_GET_PARAM_STR(q->hdfrcv, "ip", ip);
    
    struct cache *cd = e->cd;

    if (cache_getf(cd, &val, &vsize, PREFIX_PLACE"%s", ip)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        char *s = strdup(ip);
        char *dupip = s, *p = s;
        while (*p != '\0') {
            if (*p == ',') {
                *p = '\0';
                sprintf(tok, "%d", count);
                ip2place(q->hdfsnd, s, tok);
                count++;
                s = p+1;
            }
            p++;
        }
        sprintf(tok, "%d", count);
        ip2place(q->hdfsnd, s, tok);
        free(dupip);

        CACHE_HDF(q->hdfsnd, 0, PREFIX_PLACE"%s", ip);
    }
    
    return STATUS_OK;
}
Example #7
0
static NEOERR* aux_cmd_impget(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    NEOERR *err;
    char *aname;
    int aid, count, offset;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);

    mmisc_pagediv(q->hdfrcv, NULL, &count, &offset, NULL, q->hdfsnd);

    if (cache_getf(cd, &val, &vsize, PREFIX_IMP"%d_%d", aid, offset)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        MMISC_PAGEDIV_SET_N(q->hdfsnd, db, "improve", "aid=%d", NULL, aid);

        MDB_QUERY_RAW(db, "improve", IMP_COL, "aid=%d ORDER BY id DESC LIMIT "
                      " %d OFFSET %d", NULL, aid, count, offset);
        err = mdb_set_rows(q->hdfsnd, db, IMP_COL, "imps", "0");
        if (err != STATUS_OK) return nerr_pass(err);

        CACHE_HDF(q->hdfsnd, IMP_CC_SEC, PREFIX_IMP"%d_%d", aid, offset);
    }
    
    return STATUS_OK;
}
Example #8
0
/*
 * input : aname(STR)
 * return: NORMAL REP_ERR_NREGIST
 * reply : NULL
 */
static NEOERR* aic_cmd_appdel(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname;
    int aid, pid = 0;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);

    aid = hash_string(aname);

    err = aic_cmd_appinfo(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (!hdf_get_obj(q->hdfsnd, "state"))
        return nerr_raise(REP_ERR_NREGIST, "%s not regist", aname);
    pid = hdf_get_int_value(q->hdfsnd, "pid", 0);

    MDB_EXEC(db, NULL, "DELETE FROM appinfo WHERE aid=%d;", NULL, aid);
    
    cache_delf(cd, PREFIX_APPINFO"%d", aid);
    if (pid > 0) {
        cache_delf(cd, PREFIX_APPOUSER"%d_0", pid);
    }

    return STATUS_OK;
}
Example #9
0
/*
 * input : aname(STR)
 * return: NORMAL
 * reply : [appfoo: ["aid": "222", "aname": "appfoo", ...]
 */
static NEOERR* aic_cmd_appusers(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int aid, lm = 0;
    char *aname;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_FETCH_PARAM_INT(q->hdfrcv, "limit", lm);
    aid = hash_string(aname);
    
    if (cache_getf(cd, &val, &vsize, PREFIX_USERLIST"%d", aid)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        if (lm > 0) {
            MDB_QUERY_RAW(db, "userinfo", USERINFO_COL,
                          "aid=%d ORDER BY uptime DESC LIMIT %d;",
                          NULL, aid, lm);
        } else {
            MDB_QUERY_RAW(db, "userinfo", USERINFO_COL,
                          "aid=%d ORDER BY uptime DESC;", NULL, aid);
        }
        err = mdb_set_rows(q->hdfsnd, db, USERINFO_COL, "userlist", "1");
        if (err != STATUS_OK) return nerr_pass(err);
        CACHE_HDF(q->hdfsnd, AIC_CC_SEC, PREFIX_USERLIST"%d", aid);
    }
    
    return STATUS_OK;
}
Example #10
0
static NEOERR* aux_cmd_emailadd(struct aux_entry *e, QueueEntry *q)
{
    STRING str; string_init(&str);
    char sum[LEN_MD5], *content;
    NEOERR *err;
    mdb_conn *db = e->db;

    REQ_GET_PARAM_STR(q->hdfrcv, "content", content);
    
    mstr_md5_str(content, sum);
    hdf_set_value(q->hdfrcv, "checksum", sum);

    HDF *node = hdf_get_child(q->hdfrcv, "mto");

insert:
    if (node) hdf_set_value(q->hdfrcv, "to", hdf_obj_value(node));
    
    err = mdb_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.email"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO email %s", NULL, str.buf);
    string_clear(&str);

    if (node) {
        node = hdf_obj_next(node);
        if (node) goto insert;
    }

    return STATUS_OK;
}
Example #11
0
static NEOERR* aic_cmd_app_setrlink(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname, *rlink;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_GET_PARAM_STR(q->hdfrcv, "rlink", rlink);

    err = aic_cmd_appinfo(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (!hdf_get_value(q->hdfsnd, "email", NULL))
        return nerr_raise(REP_ERR_MISSEMAIL, "%s have no email supplied", aname);

    MDB_EXEC(db, NULL, "SELECT merge_appreset($1::varchar(256), $2::varchar(256));",
             "ss", aname, rlink);

    return STATUS_OK;
}
Example #12
0
static NEOERR* aic_cmd_app_getrlink(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);

    MDB_QUERY_RAW(db, "appreset", RESET_COL, "aname=$1", "s", aname);
    err = mdb_set_row(q->hdfsnd, db, RESET_COL, NULL);
    if (nerr_handle(&err, NERR_NOT_FOUND))
        return nerr_raise(REP_ERR_NRESET, "%s hasn't reseted", aname);

    return nerr_pass(err);
}
Example #13
0
static NEOERR* aic_cmd_appuserout(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *uname, *aname;
    int aid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);

    err = aic_cmd_appusers(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (!hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname))
        return nerr_raise(REP_ERR_NOTJOIN, "%s not join %s", uname, aname);

    MDB_EXEC(db, NULL, "DELETE FROM userinfo WHERE uid=%d AND aid=%d;",
             NULL, hash_string(uname), aid);

    cache_delf(cd, PREFIX_USERLIST"%d", aid);

    return STATUS_OK;
}
Example #14
0
/*
 * input : aname(STR) asn(STR) masn(STR) email(STR) state(INT)
 * return: NORMAL REP_ERR_ALREADYREGIST
 * reply : NULL
 */
static NEOERR* aic_cmd_appnew(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname, *pname, *asn, *masn, *email;
    int aid, pid = 0, state;
    NEOERR *err;

    REQ_GET_PARAM_INT(q->hdfrcv, "state", state);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_GET_PARAM_STR(q->hdfrcv, "asn", asn);
    REQ_GET_PARAM_STR(q->hdfrcv, "masn", masn);
    REQ_GET_PARAM_STR(q->hdfrcv, "email", email);

    REQ_FETCH_PARAM_STR(q->hdfrcv, "pname", pname);

    aid = hash_string(aname);
    if (pname) pid = hash_string(pname);

    err = aic_cmd_appinfo(q, cd, db);
    nerr_handle(&err, REP_ERR_NREGIST);
    if (err != STATUS_OK) return nerr_pass(err);

    if (hdf_get_obj(q->hdfsnd, "state"))
        return nerr_raise(REP_ERR_ALREADYREGIST, "%s already regist", aname);

    MDB_EXEC(db, NULL, "INSERT INTO appinfo (aid, aname, "
             " pid, asn, masn, email, state) "
             " VALUES ($1, $2::varchar(256), $3, $4::varchar(256), "
             " $5::varchar(256), $6::varchar(256), $7);",
             "isisssi", aid, aname, pid, asn, masn, email, state);
    
    cache_delf(cd, PREFIX_APPINFO"%d", aid);
    if (pid > 0) {
        cache_delf(cd, PREFIX_APPOUSER"%d_0", pid);
    }

    return STATUS_OK;
}
Example #15
0
NEOERR* base_cmd_quit(struct base_info *binfo, QueueEntry *q)
{
    char *uid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "userid", uid);

    base_user_quit(binfo, uid, NULL, NULL);
    
    hdf_set_value(q->hdfsnd, "success", "1");

    if (!(q->req->flags & FLAGS_SYNC)) {
        err = base_msg_touser("logout", q->hdfsnd, q->req->fd);
        if (err != STATUS_OK) return nerr_pass(err);
    }

    return STATUS_OK;
}
Example #16
0
/*
 * input : aname(STR) [asn(STR) masn(STR) email(STR) state(INT)]
 * return: NORMAL REP_ERR_ALREADYREGIST
 * reply : NULL
 */
static NEOERR* aic_cmd_appup(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname;
    int aid, pid = 0, tune = -1;
    STRING str;    string_init(&str);
    NEOERR *err;
    
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_FETCH_PARAM_INT(q->hdfrcv, "tune", tune);
    if (tune != -1) {
        if (hdf_get_int_value(q->hdfrcv, "tuneop", 0)) {
            /* set tune bit */
            string_appendf(&str, " tune=tune | %d ", tune);
        } else {
            /* unset tune bit */
            string_appendf(&str, " tune=tune & %d ", ~tune);
        }
    }

    aid = hash_string(aname);
    err = aic_cmd_appinfo(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (!hdf_get_obj(q->hdfsnd, "state"))
        return nerr_raise(REP_ERR_NREGIST, "%s %d hasn't regist", aname, aid);
    pid = hdf_get_int_value(q->hdfsnd, "pid", 0);

    err = mcs_build_upcol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".UpdateCol.appinfo"), &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "UPDATE appinfo SET %s WHERE aid=%d;", NULL, str.buf, aid);

    /* TODO memory leak, if exec() failure */
    string_clear(&str);
    
    cache_delf(cd, PREFIX_APPINFO"%d", aid);
    if (pid > 0) {
        cache_delf(cd, PREFIX_APPOUSER"%d_0", pid);
    }

    return STATUS_OK;
}
Example #17
0
static NEOERR* aux_cmd_mailadd(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    char sum[LEN_MD5], *content;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "content", content);
    mutil_md5_str(content, sum);
    hdf_set_value(q->hdfrcv, "checksum", sum);

    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.email"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(db, NULL, "INSERT INTO email %s", NULL, str.buf);
    string_clear(&str);

    return STATUS_OK;
}
Example #18
0
static NEOERR* aic_cmd_appousers(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int count, offset;
    int pid;
    char *pname, *aname;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "pname", pname);
    pid = hash_string(pname);
    
    mmisc_pagediv(q->hdfrcv, NULL, &count, &offset, NULL, q->hdfsnd);
    
    if (cache_getf(cd, &val, &vsize, PREFIX_APPOUSER"%d_%d", pid, offset)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        MMISC_PAGEDIV_SET_N(q->hdfsnd, db, "appinfo", "pid=%d OR aid=%d",
                            NULL, pid, pid);
        MDB_QUERY_RAW(db, "appinfo", APPINFO_COL,
                      "pid=%d OR aid=%d ORDER BY uptime DESC LIMIT %d OFFSET %d",
                      NULL, pid, pid, count, offset);
        err = mdb_set_rows(q->hdfsnd, db, APPINFO_COL, "users", "1");
        if (err != STATUS_OK) return nerr_pass(err);
        HDF *node = hdf_get_child(q->hdfsnd, "users");
        while (node) {
            /* numcamer */
            aname = hdf_get_value(node, "aname", NULL);
            if (aname) {
                MDB_QUERY_RAW(db, "userinfo", " COUNT(*) AS numcamer ",
                              "aid=%d", NULL, hash_string(aname));
                err = mdb_set_row(node, db, " numcamer ", NULL);
                if (err != STATUS_OK) return nerr_pass(err);
            }
            node = hdf_obj_next(node);
        }
        CACHE_HDF(q->hdfsnd, AIC_CC_SEC, PREFIX_APPOUSER"%d_%d", pid, offset);
    }
    
    return STATUS_OK;
}
Example #19
0
static NEOERR* aux_cmd_impadd(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    NEOERR *err;
    char *aname;
    int aid;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);
    hdf_set_int_value(q->hdfrcv, "aid", aid);

    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.improve"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(db, NULL, "INSERT INTO improve %s", NULL, str.buf);
    string_clear(&str);

    cache_delf(cd, PREFIX_IMP"%d_0", aid);
    
    return STATUS_OK;
}
Example #20
0
static NEOERR* city_cmd_ip(struct city_entry *e, QueueEntry *q)
{
	unsigned char *val = NULL; size_t vsize = 0;
    char *ip, *c, *a, *s;
	NEOERR *err;

    struct cache *cd = e->cd;
    
    REQ_GET_PARAM_STR(q->hdfrcv, "ip", ip);

    if (cache_getf(cd, &val, &vsize, PREFIX_CITY"%s", ip)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        if (!ip2place(q->hdfsnd, ip, NULL))
            return nerr_raise(NERR_ASSERT, "%s not ip", ip);
        c = hdf_get_value(q->hdfsnd, "c", NULL);
        a = hdf_get_value(q->hdfsnd, "a", NULL);
        s = strstr(c, "省");
        if (!s) s = strstr(c, "区");
        if (s) {
            s += 3;
            char tok[64] = {0};
            strncpy(tok, c, s-c);
            hdf_set_value(q->hdfrcv, "p", tok);
            hdf_set_value(q->hdfrcv, "c", s);
        } else {
            mtc_err("%s doesn't contain 省/区(%s)", c, a);
            hdf_set_value(q->hdfrcv, "c", c);
        }
        err = city_cmd_s(e, q);
        if (err != STATUS_OK) return nerr_pass(err);

        CACHE_HDF(q->hdfsnd, CITY_CC_SEC, PREFIX_CITY"%s", ip);
    }
    
    return STATUS_OK;
}
Example #21
0
/*
 * input : aname(STR)
 * return: NORMAL
 * reply : ["state": 0, ...] OR []
 */
static NEOERR* aic_cmd_appinfo(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int aid, pid;
    char *aname;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);

    if (cache_getf(cd, &val, &vsize, PREFIX_APPINFO"%d", aid)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        hdf_set_value(q->hdfsnd, "pname", aname);
        MDB_QUERY_RAW(db, "appinfo", APPINFO_COL, "aid=%d", NULL, aid);
        err = mdb_set_row(q->hdfsnd, db, APPINFO_COL, NULL);
        if (nerr_handle(&err, NERR_NOT_FOUND))
            return nerr_raise(REP_ERR_NREGIST, "%s %d hasn't regist", aname, aid);
        if (err != STATUS_OK) return nerr_pass(err);
        pid = hdf_get_int_value(q->hdfsnd, "pid", 0);
        if (pid != 0) {
            MDB_QUERY_RAW(db, "appinfo", "aname", "aid=%d", NULL, pid);
            err = mdb_set_row(q->hdfsnd, db, "pname", NULL);
            nerr_handle(&err, NERR_NOT_FOUND);
            if (err != STATUS_OK) return nerr_pass(err);
        }
        MDB_QUERY_RAW(db, "appinfo", "COUNT(*)+1 AS numuser", "pid=%d",
                      NULL, aid);
        err = mdb_set_row(q->hdfsnd, db, "numuser", NULL);
        if (err != STATUS_OK) return nerr_pass(err);

        CACHE_HDF(q->hdfsnd, AIC_CC_SEC, PREFIX_APPINFO"%d", aid);
    }
    
    return STATUS_OK;
}
Example #22
0
static NEOERR* aic_cmd_app_getsecy(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    char *aname;
    int aid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);

    if (cache_getf(cd, &val, &vsize, PREFIX_SECY"%d", aid)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        MDB_QUERY_RAW(db, "appinfo", " aname ",
                      " (aid=%d OR pid=%d) AND tune & %d = %d ",
                      NULL, aid, aid, LCS_TUNE_SECY, LCS_TUNE_SECY);
        err = mdb_set_row(q->hdfsnd, db, " aname ", NULL);
        nerr_handle(&err, NERR_NOT_FOUND);
        if (err != STATUS_OK) return nerr_pass(err);
        CACHE_HDF(q->hdfsnd, AIC_CC_SEC, PREFIX_SECY"%d", aid);
    }

    return STATUS_OK;
}
Example #23
0
static NEOERR* city_cmd_s(struct city_entry *e, QueueEntry *q)
{
	unsigned char *val = NULL; size_t vsize = 0;
    char *p = NULL, *c;
	NEOERR *err;

    mdb_conn *db = e->db;
    struct cache *cd = e->cd;

    REQ_GET_PARAM_STR(q->hdfrcv, "c", c);
    REQ_FETCH_PARAM_STR(q->hdfrcv, "p", p);

    if (cache_getf(cd, &val, &vsize, PREFIX_CITY"%s.%s", p, c)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        if (p) {
            char tok[64] = {0};
            strncpy(tok, p, 64);
            if (!strstr(p, "省") && !strstr(p, "区"))
                snprintf(tok, sizeof(tok), "%s省", p);

            MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", tok);
            mdb_set_row(q->hdfsnd, db, _COL_CITY, "province", MDB_FLAG_NO_ERR);
        }

        MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", c);
        err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z);
        if (nerr_handle(&err, NERR_NOT_FOUND)) {
            if (strstr(c, "市")) c[strlen(c)-3] = '\0';
            MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", c);
            err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys",
                               NULL, MDB_FLAG_EMPTY_OK);
        }
        if (err != STATUS_OK) return nerr_pass(err);

        /*
         * get city's parents
         */
        int cnt = 0;
        char *pid = hdf_get_valuef(q->hdfsnd, "citys.0.pid");
        while (pid && atoi(pid) > 0) {
            MDB_QUERY_RAW(db, "city", _COL_CITY, "id=%d", NULL, atoi(pid));
            err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z);
            TRACE_NOK(err);
            pid = hdf_get_valuef(q->hdfsnd, "citys.%d.pid", ++cnt);
        }
        
        /*
         * 北京市 has no subcities
         */
        /*
        int id = hdf_get_int_value(q->hdfsnd, "city.id", 0);
        MDB_QUERY_RAW(db, "city", _COL_CITY, "pid=%d", NULL, id);
        err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "subcities",
        NULL, MDB_FLAG_EMPTY_OK);
        if (err != STATUS_OK) return nerr_pass(err);
        */
        
        CACHE_HDF(q->hdfsnd, CITY_CC_SEC, PREFIX_CITY"%s.%s", p, c);
    }
    
    return STATUS_OK;
}
Example #24
0
/*
 * ids=0:1
 * { "0": { "1": { "ntt": "0", "nst": "0" } }, "success": "1" }
 *
 * ids=0:1,0:20
 * { "0": { "1": { "ntt": "0", "nst": "0" }, "20": { "ntt": "0", "nst": "0" } }, "success": "1" }
 *
 * ids=0:1,1:20
 * { "0": { "1": { "ntt": "0", "nst": "0" } }, "1": { "20": { "ntt": "0", "nst": "0" } }, "success": "1" } 
 */
static NEOERR* aux_cmd_cmtget(struct aux_entry *e, QueueEntry *q)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int count, offset;
    char *ids, *idsdump, tok[128];
    int type = -1, oid = -1;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "ids", ids);

    mdb_conn *db = e->db;
    struct cache *cd = e->cd;

    mdb_pagediv(q->hdfrcv, NULL, &count, &offset, NULL, q->hdfsnd);

    if (cache_getf(cd, &val, &vsize, PREFIX_COMMENT"%s_%d", ids, offset)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        idsdump = strdup(ids);
        char *p = ids;
        while (*p) {
            if (*p == ':') {
                *p = '\0';
                type = atoi(ids);
                ids = p+1;
            }
            if (*p == ',') {
                *p = '\0';
                oid = atoi(ids);
                if (type >= 0 && oid >= 0) {
                    sprintf(tok, "%d.%d", type, oid);
                    MDB_PAGEDIV_SET(q->hdfsnd, tok, db, "comment",
                                    "type=%d AND statu=%d AND oid=%d",
                                      NULL, type, CMT_ST_NORMAL, oid);
                    MDB_QUERY_RAW(db, "comment", _COL_CMT,
                                  "type=%d AND statu=%d AND oid=%d "
                                  " ORDER BY intime DESC LIMIT %d OFFSET %d",
                                  NULL, type, CMT_ST_NORMAL, oid, count, offset);
                    sprintf(tok, "%d.%d.cmts", type, oid);
                    err = mdb_set_rows(q->hdfsnd, db, _COL_CMT, tok, NULL);
                    nerr_handle(&err, NERR_NOT_FOUND);
                    if (err != STATUS_OK) return nerr_pass(err);
                    mstr_html_escape(hdf_get_child(q->hdfsnd, tok), "content");
                    type = oid = -1;
                }
                ids = p+1;
            }
            p++;
        }
        oid = atoi(ids);
        if (type >= 0 && oid >=0) {
            sprintf(tok, "%d.%d", type, oid);
            MDB_PAGEDIV_SET(q->hdfsnd, tok, db, "comment",
                            "type=%d AND statu=%d AND oid=%d",
                            NULL, type, CMT_ST_NORMAL, oid);
            MDB_QUERY_RAW(db, "comment", _COL_CMT,
                          "type=%d AND statu=%d AND oid=%d "
                          " ORDER BY intime DESC LIMIT %d OFFSET %d",
                          NULL, type, CMT_ST_NORMAL, oid, count, offset);
            sprintf(tok, "%d.%d.cmts", type, oid);
            err = mdb_set_rows(q->hdfsnd, db, _COL_CMT, tok, NULL);
            nerr_handle(&err, NERR_NOT_FOUND);
            if (err != STATUS_OK) return nerr_pass(err);
            mstr_html_escape(hdf_get_child(q->hdfsnd, tok), "content");
        }
        
        CACHE_HDF(q->hdfsnd, CMT_CC_SEC, PREFIX_COMMENT"%s_%d", idsdump, offset);
        free(idsdump);
    }

    return STATUS_OK;
}