Beispiel #1
0
NEOERR* blog_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname, *author;
    NEOERR *err;

    LPRE_DBOP(cgi->hdf, conn);

    APP_CHECK_LOGIN();

    if (hdf_get_int_value(evt->hdfrcv, "state", 0) < LCS_ST_ADMIN)
        return nerr_raise(LERR_LIMIT, "%s wan't be admin", aname);

    int bid = hdf_get_int_value(cgi->hdf, PRE_QUERY".bid", 0);
    /* just rend tpl */
    if (bid == 0) return STATUS_OK;

    MDB_QUERY_RAW(conn, "blog", BLOG_COL, " id=%d ",
                  NULL, bid, BLOG_ST_NORMAL);
    err = mdb_set_row(cgi->hdf, conn, BLOG_COL, PRE_OUTPUT".blog");
    if (err != STATUS_OK) return nerr_pass(err);

    author = hdf_get_value(cgi->hdf, PRE_OUTPUT".blog.author", NULL);
    if (!author) return nerr_raise(LERR_MISS_DATA, "%s not exist", aname);
    
    if (strcmp(aname, author))
        return nerr_raise(LERR_LIMIT, "%s not %s", aname, author);

    return STATUS_OK;
}
Beispiel #2
0
NEOERR* blog_index_static_get(HDF *hdf, HASH *dbh)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    NEOERR *err;

    LPRE_DBOP(hdf, conn);

    /* set pgtt for caller use */
    MMISC_PAGEDIV_SET(hdf, PRE_OUTPUT, conn, "blog", " state=%d ",
                      NULL, BLOG_ST_NORMAL);
    int ntt = hdf_get_int_value(hdf, PRE_OUTPUT".ntt", 0);
    int pgtt = (ntt+BLOG_NUM_PERPAGE-1) / BLOG_NUM_PERPAGE;
    hdf_set_int_value(hdf, PRE_OUTPUT".pgtt", pgtt);
    
    int offset = 0;
    int pageid = hdf_get_int_value(hdf, PRE_QUERY".pageid", 0);
    if (pageid == 0)
        offset = (pgtt - 1) * BLOG_NUM_PERPAGE;
    else
        offset = (pageid-1) * BLOG_NUM_PERPAGE;
    MDB_QUERY_RAW(conn, "blog", BLOG_COL, " state=%d ORDER BY ID "
                  " LIMIT %d OFFSET %d", NULL,
                  BLOG_ST_NORMAL, BLOG_NUM_PERPAGE, offset);

    return nerr_pass(mdb_set_rows(hdf, conn, BLOG_COL, PRE_OUTPUT".blogs", "0"));
}
Beispiel #3
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;
}
Beispiel #4
0
bool mtc_msg(const char *func, const char *file, long line,
             int level, const char *format, ...)
{
    int dftlv = hdf_get_int_value(g_cfg, PRE_CONFIG".trace_level", TC_DEFAULT_LEVEL);
    if (level > dftlv)
        return true;
    
    if (g_fp == NULL)
        return false;

    va_list ap;
    char tm[LEN_TM];
    mutil_getdatetime(tm, sizeof(tm), "%Y-%m-%d %H:%M:%S", time(NULL));

    fprintf(g_fp, "[%s]", tm);
    fprintf(g_fp, "[%s]", g_trace_level[level]);
    fprintf(g_fp, "[%s:%li %s] ", file, line, func);

    va_start(ap, (void*)format);
    vfprintf(g_fp, format, ap);
    va_end(ap);

    fprintf(g_fp, "\n");

    trace_shift_file();
    return true;
}
Beispiel #5
0
NEOERR* inbox_multi_add(HDF *datanode, HASH *evth, char *inboxtype)
{
    mevent_t *evt;
    int mid;
    HDF *child;
    NEOERR *err;
    
    MCS_NOT_NULLB(datanode, evth);

    evt = hash_lookup(evth, "aux");
    MCS_NOT_NULLA(evt);

    child = hdf_obj_child(datanode);
    while (child) {
        mid = hdf_get_int_value(child, "mid", 0);
        if (mid > 0) {
            hdf_set_valuef(evt->hdfsnd, "mmid.%d=%d", mid, mid);
        }

        child = hdf_obj_next(child);
    }

    if (!hdf_get_obj(evt->hdfsnd, "mmid"))
        return nerr_raise(NERR_ASSERT, "请设置收信用户号码");

    err = mtpl_InConfigRend_get(evt->hdfsnd, datanode, "inbox", inboxtype, g_datah);
	if (err != STATUS_OK) return nerr_pass(err);
    
    MEVENT_TRIGGER(evt, NULL, REQ_CMD_AUX_INBOX_ADD, FLAGS_NONE);

    return STATUS_OK;
}
Beispiel #6
0
NEOERR* blog_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname;
    int bid;
    NEOERR *err;

    LPRE_DBOP(cgi->hdf, conn);

    HDF_GET_INT(cgi->hdf, PRE_QUERY".bid", bid);

    APP_CHECK_LOGIN();
    
    if (hdf_get_int_value(evt->hdfrcv, "state", 0) < LCS_ST_ADMIN)
        return nerr_raise(LERR_LIMIT, "%s wan't be admin", aname);

    STRING str;
    string_init(&str);
    err = mcs_build_upcol(hdf_get_obj(cgi->hdf, PRE_QUERY),
                          hdf_get_obj(g_cfg, "Db.UpdateCol.blog"), &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(conn, NULL, "UPDATE blog SET %s WHERE id=%d AND author=$1",
             "s", str.buf, bid, aname);
    string_clear(&str);

    char command[1024];
    snprintf(command, sizeof(command), PATH_PAGER"blg -b %d", bid);
    mtc_dbg("%s", command);
    system(command);

    return STATUS_OK;
}
Beispiel #7
0
NEOERR* blog_data_add(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname, command[1024];
    char *title, *content;
    int id = 0;
    NEOERR *err;

    LPRE_DBOP(cgi->hdf, conn);
    
    APP_CHECK_LOGIN();
    
    if (hdf_get_int_value(evt->hdfrcv, "state", 0) < LCS_ST_ADMIN)
        return nerr_raise(LERR_LIMIT, "%s wan't be admin", aname);

    HDF_GET_STR(cgi->hdf, PRE_QUERY".title", title);
    HDF_GET_STR(cgi->hdf, PRE_QUERY".content", content);

    MDB_EXEC(conn, NULL, "INSERT INTO blog (title, content, author) "
             " VALUES ($1::varchar(256), $2, "
             " $3::varchar(256)) RETURNING id",
             "sss", title, content, aname);
    err = mdb_get(conn, "i", &id);
    if (err != STATUS_OK) return nerr_pass(err);

    snprintf(command, sizeof(command), PATH_PAGER"blg -i 0 -b %d", id);
    mtc_dbg("%s", command);
    system(command);

    return STATUS_OK;
}
Beispiel #8
0
NEOERR* blog_data_del(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname;
    int bid, state;
    NEOERR *err;

    LPRE_DBOP(cgi->hdf, conn);

    HDF_GET_INT(cgi->hdf, PRE_QUERY".bid", bid);
    HDF_GET_INT(cgi->hdf, PRE_QUERY".state", state);

    APP_CHECK_LOGIN();
    
    if (hdf_get_int_value(evt->hdfrcv, "state", 0) < LCS_ST_ADMIN)
        return nerr_raise(LERR_LIMIT, "%s wan't be admin", aname);

    MDB_EXEC(conn, NULL, "UPDATE blog SET state=%d WHERE id=%d AND "
             " author=$1", "s", state, bid, aname);

    char command[1024];
    snprintf(command, sizeof(command), PATH_PAGER"blg -b %d", bid);
    mtc_dbg("%s", command);
    system(command);

    if (state == BLOG_ST_DEL) {
        snprintf(command, sizeof(command), "rm -f %s/%d/%d.html",
                 PATH_BLOG, bid%BLOG_SUBDIR_NUM, bid);
        mtc_dbg("%s", command);
        system(command);
    }

    return STATUS_OK;
}
Beispiel #9
0
NEOERR* blog_static_get(HDF *hdf, HASH *dbh)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    NEOERR *err;

    LPRE_DBOP(hdf, conn);

    int bid = hdf_get_int_value(hdf, PRE_QUERY".bid", 0);

    MDB_QUERY_RAW(conn, "blog", BLOG_COL, " id=%d AND state=%d ",
                  NULL, bid, BLOG_ST_NORMAL);
    err = mdb_set_row(hdf, conn, BLOG_COL, PRE_OUTPUT".blog");
    if (err != STATUS_OK) return nerr_pass(err);

    /*
     * previous
     * TODO id%32 ===> id%%d, BLOG_SUBDIR_NUM
     */
    MDB_QUERY_RAW(conn, "blog", " id%32 ||'/'|| id as id, title ",
                  " id < %d AND state=%d ORDER BY ID DESC LIMIT 1 ",
                  NULL, bid, BLOG_ST_NORMAL);
    err = mdb_set_row(hdf, conn, " fnameprev, titleprev ", PRE_OUTPUT".blog");
    if (err != STATUS_OK) return nerr_pass(err);

    /*
     * next 
     */
    MDB_QUERY_RAW(conn, "blog", " id%32 ||'/'|| id as id, title ",
                  " id > %d AND state=%d ORDER BY ID LIMIT 1 ",
                  NULL, bid, BLOG_ST_NORMAL);
    err = mdb_set_row(hdf, conn, " fnamenext, titlenext ", PRE_OUTPUT".blog");

    return nerr_pass(err);
}
Beispiel #10
0
static EventEntry* skeleton_init_driver(void)
{
    struct skeleton_entry *e = calloc(1, sizeof(struct skeleton_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = skeleton_process_driver;
    e->base.stop_driver = skeleton_stop_driver;
    //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term);

    //char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    //err = mdb_init(&e->db, s);
    //JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (EventEntry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
Beispiel #11
0
NEOERR* oms_bill_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname;
    NEOERR *err;

    APP_CHECK_ADMIN();
    SET_ADMIN_ACTION(evt->hdfrcv, cgi->hdf);

    hdf_copy(cgi->hdf, PRE_OUTPUT".appinfo", evt->hdfrcv);

    int state = hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE);
    if (state <= LCS_ST_FREE) return STATUS_OK;

    evt = hash_lookup(evth, "bank");
    hdf_set_value(evt->hdfsnd, "aname", aname);
    MEVENT_TRIGGER(evt, aname, REQ_CMD_BANK_INFO, FLAGS_SYNC);
    hdf_copy(cgi->hdf, PRE_OUTPUT".bankinfo", evt->hdfrcv);

    hdf_set_value(evt->hdfsnd, "aname", aname);
    hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY));
    MEVENT_TRIGGER(evt, aname, REQ_CMD_BANK_GETBILL, FLAGS_SYNC);
    hdf_copy(cgi->hdf, PRE_OUTPUT, evt->hdfrcv);

    return STATUS_OK;
}
Beispiel #12
0
static struct event_entry* aic_init_driver(void)
{
    struct aic_entry *e = calloc(1, sizeof(struct aic_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = aic_process_driver;
    e->base.stop_driver = aic_stop_driver;

    char *dbsn = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    err = mdb_init(&e->db, dbsn);
    JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (struct event_entry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
Beispiel #13
0
NEOERR* session_init(CGI *cgi, HASH *dbh, session_t **ses)
{
    session_t *lses;
    char tok[_POSIX_PATH_MAX];
    
    *ses = NULL;

    lses = calloc(1, sizeof(session_t));
    if (!lses) return nerr_raise(NERR_NOMEM, "calloc memory for session_t failure");
    
    lses->reqtype = CGI_REQ_HTML;
    hdf_get_copy(cgi->hdf, PRE_COOKIE".uname", &lses->uname, NULL);

    char *uri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, NULL);
    if (!uri) {
        uri = "terminal";
        lses->reqtype = CGI_REQ_TERMINAL;
    }
    /* TODO uniq req uri */
    //uri = mmisc_str_uniq(uri, '/');
    mmisc_str_repchr(uri, '/', '_');
    uri = mmisc_str_strip(uri, '_');
    if (!strncmp(uri, "json_", 5)) {
        uri = uri+5;
        lses->reqtype = CGI_REQ_AJAX;
    }
    switch (CGI_REQ_METHOD(cgi)) {
        case CGI_REQ_POST:
            snprintf(tok, sizeof(tok), "%s_data_mod", uri);
            break;
        case CGI_REQ_PUT:
            snprintf(tok, sizeof(tok), "%s_data_add", uri);
            break;
        case CGI_REQ_DEL:
            snprintf(tok, sizeof(tok), "%s_data_del", uri);
            break;
        default:
        case CGI_REQ_GET:
            snprintf(tok, sizeof(tok), "%s_data_get", uri);
            break;
    }
    lses->dataer = strdup(tok);
    lses->render = strdup(uri);
    
    /* process cache */
    HDF *node = hdf_get_obj(g_cfg, PRE_CFG_FILECACHE".0");
    while (node != NULL) {
        if (reg_search(hdf_get_value(node, "uri", "NULL"), uri)) {
            lses->tm_cache_browser = hdf_get_int_value(node, "tm_cache", 0);
            break;
        }
        node = hdf_obj_next(node);
    }

    *ses = lses;
    
    return STATUS_OK;
}
Beispiel #14
0
int mcs_add_int_value(HDF *node, char *key, int val)
{
    if (!node || !key) return 0;
    
    int ov = hdf_get_int_value(node, key, 0);
    hdf_set_int_value(node, key, ov+val);

    return ov+val;
}
Beispiel #15
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;
}
Beispiel #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;
}
Beispiel #17
0
int mcs_get_int_valuef(HDF *hdf, int defval, char *fmt, ...)
{
    char key[LEN_HDF_KEY];
    va_list ap;

    va_start(ap, fmt);
    vsnprintf(key, sizeof(key), fmt, ap);
    va_end(ap);

    return hdf_get_int_value(hdf, key, defval);
}
Beispiel #18
0
struct mevent* mevent_start(void)
{
    int ret;

    struct mevent *evt = calloc(1, sizeof(struct mevent));
    if (evt == NULL) return NULL;

    evt->numevts = 0;
    evt->chainlen = 1000000;
    //evt->hashlen = evt->numevts / evt->chainlen;
    evt->hashlen = 16;
    evt->table = calloc(evt->hashlen, sizeof(struct event_chain));

    void *lib;
    char tbuf[1024], *tp;
    char *name;
    int num_thread;
    struct event_driver *driver;
    HDF *res = hdf_get_child(g_cfg, PRE_SERVER".plugins");
    char *plugin_path = settings.plugin_path ? settings.plugin_path : PLUGIN_PATH;
    while (res != NULL) {
        lib = NULL; driver = NULL; memset(tbuf, 0x0, sizeof(tbuf));
        name = hdf_get_value(res, "name", "_unexist");
        num_thread = hdf_get_int_value(res, "numberofthreads", 1);
        HDF *mates = hdf_get_obj(res, "mates");

        snprintf(tbuf, sizeof(tbuf), "%s/mevent_%s.so", plugin_path, name);
        //lib = dlopen(tbuf, RTLD_NOW|RTLD_GLOBAL);
        lib = dlopen(tbuf, RTLD_LAZY|RTLD_GLOBAL);
        if (lib == NULL) {
            wlog("open driver %s failure %s\n", tbuf, dlerror());
            res = hdf_obj_next(res);
            continue;
        }

        snprintf(tbuf, sizeof(tbuf), "%s_driver", name);
        driver = (struct event_driver*)dlsym(lib, tbuf);
        if ((tp = dlerror()) != NULL) {
            wlog("find symbol %s failure %s\n", tbuf, tp);
            res = hdf_obj_next(res);
            continue;
        }

        ret = mevent_start_driver(evt, driver, lib, num_thread, mates);
        if (ret != 1) wlog("init driver %s failure\n", name);
        else evt->numevts++;

        res = hdf_obj_next(res);
    }

    return evt;
}
Beispiel #19
0
NEOERR* mhttp_upload_parse_cb(CGI *cgi, char *method, char *ctype, void *rock)
{
    MCS_NOT_NULLC(cgi, method, ctype);

    if (!strcasecmp(method, "GET"))
        return nerr_raise(CGIParseNotHandled, "%s not handled", method);

    int len = hdf_get_int_value(cgi->hdf, "CGI.ContentLength", 0);

    if (len <= 0 || len > *(int*)rock)
        return nerr_raise(CGIUploadCancelled, "content length %d not support", len);

    return STATUS_OK;
}
Beispiel #20
0
static PyObject * p_hdf_get_int_value (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv;
  char *name;
  int r, d = 0;

  if (!PyArg_ParseTuple(args, "si:getIntValue(name, default)", &name, &d))
    return NULL;

  r = hdf_get_int_value (ho->data, name, d);
  rv = Py_BuildValue ("i", r);
  return rv;
}
Beispiel #21
0
NEOERR* comment_data_add(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aux");
    mevent_t *evt_place = (mevent_t*)hash_lookup(evth, "place");

    LPRE_EVTOP(cgi->hdf, evt);

    /*
     * TODO other user can't comment on my improve...
     */
#if 0
    HDF_GET_INT(cgi->hdf, PRE_QUERY".type", type);
    if (type == CMT_TYPE_IMPROVE) {
        APP_CHECK_LOGIN();
        state = hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE);
        if (state < LCS_ST_ADMIN && ())
    }
Beispiel #22
0
static void plan_prepare_time(HDF *node, char *date, struct tm *todaystm, float km)
{
    if (!node || !date || !todaystm) return;

    char datetime[LEN_TM] = {0}, *stime, *sdate;
    time_t tm;

    /*
     * epochsec seted, so, return
     */
    if (hdf_get_value(node, "epochsec", NULL)) return;
    
    stime = hdf_get_value(node, "stime", "08:00:00");
    sdate = hdf_get_value(node, "sdate", "2011-11-11");
    
    int repeat = hdf_get_int_value(node, "repeat", PLAN_RPT_NONE);
    if (repeat == PLAN_RPT_DAY) {
        /*
         * use date as datepart
         */
        snprintf(datetime, LEN_TM, "%s %s", date, stime);
    } else if (repeat == PLAN_RPT_WEEK) {
        /*
         * use the nearest date as datepart
         */
        int minday = 7, thatday;
        /* 1,2,3,4,5 */
        if (sdate) {
            int today = todaystm->tm_wday + 1;
            ULIST *list;
            
            string_array_split(&list, sdate, ",", 100);
            ITERATE_MLIST(list) {
                thatday = atoi(list->items[t_rsv_i]);
                if (abs(minday) > abs(thatday - today))
                    minday = thatday - today;
            }
            uListDestroy(&list, ULIST_FREE);
        }
        tm = m_thatsec + (minday*60*60*24);
        struct tm *stm = localtime(&tm);
        char s[LEN_DT];
        strftime(s, LEN_DT, "%Y-%m-%d", stm);
        snprintf(datetime, LEN_TM, "%s %s", s, stime);
    } else {
Beispiel #23
0
JNIEXPORT jint JNICALL Java_org_clearsilver_HDF__1getIntValue(
    JNIEnv *env, jclass objClass, jint hdf_obj_ptr, jstring j_hdfname,
     jint default_value) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  int r;
  const char *hdfname;

  if (!j_hdfname) {
    throwNullPointerException(env, "hdfname argument was null");
    return 0;
  }

  hdfname = (*env)->GetStringUTFChars(env,j_hdfname, 0);

  r = hdf_get_int_value(hdf, hdfname, default_value);

  (*env)->ReleaseStringUTFChars(env,j_hdfname,hdfname);
  return r;
}
Beispiel #24
0
int file_get_files(HDF *hdf, mdb_conn *conn, session_t *ses)
{
    PRE_DBOP(hdf, conn);

    int ret, cnt = 0;
    char tok[LEN_MD];
    int count, offset, uin, pid;
    ULIST *gnode;
    gnode_t *node;
    member_t *mb;
    file_t *fl;

    pid = hdf_get_int_value(hdf, PRE_QUERY".pid", 1);

    //sprintf(tok, "pid=%d", pid);
    //mmisc_set_count(hdf, conn, "fileinfo", tok);
    mmisc_get_offset(hdf, &count, &offset);

    if (member_has_login(hdf, conn, ses) != RET_RBTOP_OK) {
        return RET_RBTOP_NOTLOGIN;
    }

    if (!member_has_gmode(ses->member, GROUP_MODE_SENIOR, GROUP_STAT_OK)) {
        mtc_warn("%d attemped to list sys-file", ses->member->uin);
        return RET_RBTOP_LIMITE;
    }

    ret = member_get_group(ses->member, GROUP_MODE_SENIOR, GROUP_STAT_OK, &gnode);
    if (ret != RET_RBTOP_OK) {
        mtc_err("get %d %d failure", ses->member->uin, GROUP_MODE_SENIOR);
        return ret;
    }

    MLIST_ITERATE(gnode, node) {
        ret = file_get_info_by_id(conn, node->gid, NULL, -1, &fl);
        if (ret != RET_RBTOP_OK) {
            mtc_err("get %d info failure", node->gid);
            continue;
        }
        sprintf(tok, "%s.files.%d", PRE_OUTPUT, cnt++);
        file_item2hdf(fl, tok, hdf);
        file_del(fl);
    }
Beispiel #25
0
static EventEntry* city_init_driver(void)
{
    struct city_entry *e = calloc(1, sizeof(struct city_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = city_process_driver;
    e->base.stop_driver = city_stop_driver;
    //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term);

    char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    err = mdb_init(&e->db, s);
    JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }

    s = hdf_get_value(g_cfg, CONFIG_PATH".ipfile", "QQWry.Dat");
    err = ne_load_file(s, (char**)&ips);
    JUMP_NOK(err, error);

    ipbgn = b2int(ips, 4);
    ipend = b2int(ips+4, 4);
    if (ipbgn < 0 || ipend < 0) {
        wlog("%s format error", s);
        goto error;
    }
    
    return (EventEntry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    if (ips) free(ips);
    free(e);
    return NULL;
}
Beispiel #26
0
NEOERR* pos_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
	STRING str; string_init(&str);
    mdb_conn *db = hash_lookup(dbh, "city");
	NEOERR *err;

    if (!cgi || !cgi->hdf || !db) return nerr_raise(NERR_ASSERT, "paramter null");

    int id = hdf_get_int_value(cgi->hdf, PRE_QUERY".id", 0);
    
    err = mdb_build_upcol(hdf_get_obj(cgi->hdf, PRE_QUERY),
                          hdf_get_obj(g_cfg, "Db.UpdateCol.city"), &str);
	if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(db, NULL, "UPDATE city SET %s WHERE id=%d;", NULL, str.buf, id);
    

    return STATUS_OK;
}
Beispiel #27
0
NEOERR* oms_edit_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname;
    NEOERR *err;

    APP_CHECK_ADMIN();

    SET_ADMIN_ACTION(evt->hdfrcv, cgi->hdf);

    err = oms_data_get(cgi, dbh, evth, ses);
    int tune = hdf_get_int_value(cgi->hdf, PRE_OUTPUT".appinfo.tune", 0);

    if (tune & LCS_TUNE_QUIET)
        hdf_set_value(cgi->hdf, PRE_OUTPUT".appinfo.quiet", "1");
    if (tune & LCS_TUNE_SMS)
        hdf_set_value(cgi->hdf, PRE_OUTPUT".appinfo.sms", "1");

    return nerr_pass(err);
}
Beispiel #28
0
static EventEntry* aux_init_driver(void)
{
    struct aux_entry *e = calloc(1, sizeof(struct aux_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = aux_process_driver;
    e->base.stop_driver = aux_stop_driver;
    //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term);

    char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    err = mdb_init(&e->db, s);
    JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }

    err = mdb_exec(e->db, NULL, "SELECT id from memory ORDER BY id DESC LIMIT 1", NULL);
    JUMP_NOK(err, error);
    err = mdb_get(e->db, "i", &m_memory_maxid);
    if (nerr_handle(&err, NERR_NOT_FOUND)) {
        mtc_err("table memory empty");
        wlog("table memory empty");
    }
    JUMP_NOK(err, error);
    
    return (EventEntry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
Beispiel #29
0
NEOERR* bore_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt_member = hash_lookup(evth, "member");
    mevent_t *evt = hash_lookup(evth, "aux");
	NEOERR *err;

    MCS_NOT_NULLB(cgi->hdf, evt);

    err = member_check_login_data_get(cgi, dbh, evth, ses);
    if (err == STATUS_OK) {
        if (hdf_get_int_value(evt_member->hdfrcv, "verify", -1) >= MEMBER_VF_ADMIN)
            SET_ADMIN_ACTION(cgi->hdf);
    }
    nerr_ignore(&err);

    hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY));

    MEVENT_TRIGGER(evt, NULL, REQ_CMD_MEMORY_GET, FLAGS_SYNC);

    hdf_copy(cgi->hdf, PRE_OUTPUT".memory", evt->hdfrcv);

    return STATUS_OK;
}
Beispiel #30
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;
}