Exemple #1
0
void mcs_hdf_rep(HDF *data, HDF *dst)
{
    char *srcstr, *repstr;
    
    if (!data || !dst) return;

    HDF *datarow = hdf_obj_child(data);
    while (datarow) {
        HDF *child = hdf_obj_child(dst);
        while (child) {
            if (hdf_obj_child(child)) {
                return mcs_hdf_rep(data, child);
            }

            srcstr = hdf_obj_value(child);
            repstr = mstr_repstr(1, srcstr,
                                 hdf_obj_name(datarow),
                                 hdf_obj_value(datarow));
            hdf_set_value(child, NULL, repstr);
            free(repstr);

            child = hdf_obj_next(child);
        }
        
        datarow = hdf_obj_next(datarow);
    }
}
Exemple #2
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;
}
/* load a specified version of the file, version -1 is latest */
NEOERR * rcfs_load (const char *path, int version, char **data)
{
  NEOERR *err;
  char fpath[_POSIX_PATH_MAX];

  if (version == -1)
  {
    HDF *meta, *vers;
    int x;

    err = rcfs_meta_load (path, &meta);
    if (err) return nerr_pass (err);
    for (vers = hdf_get_child (meta, "Versions");
	vers;
	vers = hdf_obj_next (vers))
    {
      x = atoi (hdf_obj_name (vers));
      if (x > version) version = x;
    }
    hdf_destroy (&meta);
  }
  snprintf (fpath, sizeof (fpath), "%s,%d", path, version);
  err = ne_load_file (fpath, data);
  return nerr_pass (err);
}
Exemple #4
0
NEOERR* fill_trackarea(HASH *evth, HASH *dbh)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "dyn");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "place");
    HDF *node; hdf_init(&node);
    char *ip, *aid, *uid, *city, *area;
    NEOERR *err;

    LPRE_ALLOP(node, conn, evt);

    MDB_QUERY_RAW(conn, "track", COL_TRACK, "intime > current_date AND "
                  " area='' GROUP BY aid, uid", NULL);
    err = mdb_set_rows(node, conn, COL_TRACK, NULL, NULL);
    if (err != STATUS_OK) return nerr_pass(err);

    node = hdf_obj_child(node);
    while (node) {
        ip = hdf_get_value(node, "ip", NULL);
        aid = hdf_get_value(node, "aid", "0");
        uid = hdf_get_value(node, "uid", "0");
        if (ip) {
            hdf_set_value(evt->hdfsnd, "ip", ip);
            MEVENT_TRIGGER_NRET(evt, ip, REQ_CMD_PLACEGET, FLAGS_SYNC);
            city = hdf_get_value(evt->hdfrcv, "0.c", "Mars");
            area = city2area(city);
            MDB_EXEC(conn, NULL, "UPDATE track SET area=$1 WHERE aid=$2 AND uid=$3",
                     "sss", area, aid, uid);
        }

        node = hdf_obj_next(node);
    }

    return STATUS_OK;
}
Exemple #5
0
/* The search path is part of the HDF by convention */
NEOERR* hdf_search_path (HDF *hdf, const char *path, char *full, int full_len)
{
  HDF *paths;
  struct stat s;

  for (paths = hdf_get_child (hdf, "hdf.loadpaths");
      paths;
      paths = hdf_obj_next (paths))
  {
    snprintf (full, full_len, "%s/%s", hdf_obj_value(paths), path);
    errno = 0;
    if (stat (full, &s) == -1)
    {
      if (errno != ENOENT)
	return nerr_raise_errno (NERR_SYSTEM, "Stat of %s failed", full);
    }
    else
    {
      return STATUS_OK;
    }
  }

  strncpy (full, path, full_len);
  if (stat (full, &s) == -1)
  {
    if (errno != ENOENT)
      return nerr_raise_errno (NERR_SYSTEM, "Stat of %s failed", full);
  }
  else return STATUS_OK;

  return nerr_raise (NERR_NOT_FOUND, "Path %s not found", path);
}
Exemple #6
0
void ltpl_prepare_rend(HDF *hdf, char *tpl)
{
    char key[LEN_ST];
    HDF *tmphdf, *ahdf; 
    if (hdf == NULL) return;

    /*
     * merge dataset from g_cfg 
     */
    snprintf(key, sizeof(key), PRE_CFG_DATASET".%s", tpl);
    tmphdf = hdf_get_obj(g_cfg, key);
    if (tmphdf != NULL) hdf_copy(hdf, PRE_CFG_LAYOUT, tmphdf);
    
    /*
     * special actions
     */
    tmphdf = hdf_get_child(hdf, PRE_WALK_SACTION);
    while (tmphdf) {
        snprintf(key, sizeof(key), PRE_LAYOUT".%s", hdf_obj_value(tmphdf));
        ahdf = hdf_get_obj(hdf, key);
        if (ahdf) hdf_copy(hdf, PRE_LAYOUT".actions", ahdf);
        
        tmphdf = hdf_obj_next(tmphdf);
    }
    
    /*
     * set classes
     */
    char *pos = hdf_get_value(hdf, "Layout.tabpart", NULL);
    if (pos) hdf_set_valuef(hdf, "Layout.tabs.%s.class=selected", pos);
    pos = hdf_get_value(hdf, "Layout.actionpart", NULL);
    if (pos) hdf_set_valuef(hdf, "Layout.actions.%s.class=selected", pos);
}
Exemple #7
0
static NEOERR* aux_cmd_inboxadd(struct aux_entry *e, QueueEntry *q)
{
    STRING str; string_init(&str);
    NEOERR *err;
    mdb_conn *db = e->db;

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

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

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

    return STATUS_OK;
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #10
0
NEOERR* levt_init(HASH **evth)
{
    mevent_t *evt;
    char *ename;
    HDF *node;
    HASH *levth;
    NEOERR *err;

    node = hdf_get_obj(g_cfg, "Mevent");
    if (!node) return nerr_raise(NERR_ASSERT, "Mevent config not found");

    err = hash_init(&levth, hash_str_hash, hash_str_comp, hash_str_free);
    if (err != STATUS_OK) return nerr_pass(err);

    node = hdf_obj_child(node);
    while (node != NULL) {
        ename = hdf_obj_value(node);
        evt = mevent_init_plugin(ename);
        if (evt) {
            mtc_dbg("event %s init ok", ename);
            hash_insert(levth, (void*)strdup(ename), (void*)evt);
        } else {
            mtc_err("event %s init failure", ename);
        }

        node = hdf_obj_next(node);
    }

    *evth = levth;
    return STATUS_OK;
}
Exemple #11
0
void CGI::TranslatePost(void *cgi, Tree *posts,
                        std::map<std::string, File> *files)
{
    ::CGI *c = reinterpret_cast< ::CGI *>(cgi);

    HDF *parent = hdf_get_obj(c->hdf, "Query");
    if (!parent) {
        return;
    }

    HDF *next = hdf_obj_child(parent);
    while (next) {
        HDF *child = next;
        next = hdf_obj_next(next);

        const char *k = hdf_obj_name(child);
        const char *v = hdf_obj_value(child);
        if (!k || !v) {
            continue;
        }

        if (!TranslateFile(c, k, files)) {
            posts->Set(k, v);
        }
    }
}
Exemple #12
0
Hdf Hdf::next(bool markVisited /* = true */) const {
  HDF *hdf = getRaw();
  if (markVisited) hdf_set_visited(hdf, 1);
  Hdf ret(hdf_obj_next(hdf));
  ret.m_path = m_path;
  ret.m_name = ret.getName(markVisited);
  return ret;
}
Exemple #13
0
JNIEXPORT jint JNICALL Java_org_clearsilver_HDF__1objNext(
    JNIEnv *env, jclass objClass, jint hdf_obj_ptr) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  HDF *next_hdf = NULL;

  next_hdf = hdf_obj_next(hdf);
  return (jint)next_hdf;
}
Exemple #14
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;
}
Exemple #15
0
NEOERR* member_pic_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mevent_t *evt = hash_lookup(evth, "member");
    HDF *node;
    char *s = NULL, *defs = NULL, *path, *size;

    MCS_NOT_NULLB(cgi->hdf, evt);

    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".defs", defs);
    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".fpath", path);
    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".fsize", size);

    node = hdf_get_child(cgi->hdf, PRE_QUERY".type");
    if (!node) HDF_GET_STR(cgi->hdf, PRE_QUERY".type", s);

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

    MEVENT_TRIGGER(evt, NULL, REQ_CMD_MEMBER_PRIV_GET, FLAGS_SYNC);

    if (s) goto getval;
    while (node) {
        s = hdf_obj_value(node);
getval:
        /*
         * turn &amp; into & in url format
         */
        mstr_html_unescape(evt->hdfrcv, s);
        s = hdf_get_value(evt->hdfrcv, s, NULL);
        if (s && *s) {
            if (!strncmp(s, "http:", 5)) {
                hdf_set_value(cgi->hdf, PRE_OUTPUT".302", s);
                return STATUS_OK;
            }
            break;
        }

        if (node) node = hdf_obj_next(node);
    }

    if (!s || !*s) {
        if (!defs) s = SITE_DOMAIN;
        else if (!strcmp(defs, "segv")) return STATUS_OK;
        else s = defs;
    }

    if (!path) path = hdf_get_value(g_cfg,
                                        "Config.font.member.path",
                                        "/usr/share/ttf/Times.ttf");

    if (!size) size = hdf_get_value(g_cfg, "Config.font.member.size", "14.");

    return nerr_pass(mimg_create_from_string(s, path, atof(size), &ses->data));
}
Exemple #16
0
int wkm_cfg_to_opts(struct wkman *wkman, struct cfg *cfg) {
	HDF *base_hdf = (HDF*)cfg;
	HDF *hdf;
	int rval = 0;
	dbg1("%s %s()", wkman->dev->serial, __func__);
	for(hdf = hdf_obj_child(base_hdf); hdf; hdf = hdf_obj_next(hdf)) {
		const char *key = hdf_obj_name(hdf);
		const char *val_str = hdf_obj_value(hdf);
		int val = atoi(val_str);
		rval += wkm_set_value(wkman, key, val);
	}
	return rval;
}
Exemple #17
0
HDF* mcs_get_nth_child(HDF *hdf, char *name, int n)
{
    HDF *node;
    
    if (!hdf || n < 0) return NULL;

    node = hdf_get_child(hdf, name);
    while (node && --n > 0) {
        node = hdf_obj_next(node);
    }

    return node;
}
Exemple #18
0
HDF* mcs_obj_nth_child(HDF *hdf, int n)
{
    HDF *node;

    if (!hdf || n < 0) return NULL;

    node = hdf_obj_child(hdf);
    while (node && --n > 0) {
        node = hdf_obj_next(node);
    }

    return node;
}
Exemple #19
0
int main(int argc, char **argv, char **envp)
{
    char key[10];
    HDF *bignode;

    mtc_init("cshdf", 7);

    hdf_init(&bignode);

    for (int i = 0; i < 5003929; i++) {
        mstr_rand_string_with_len(key, 10);

        hdf_set_valuef(bignode, "%s.today=10", key);
        hdf_set_valuef(bignode, "%s.toweek=11", key);
        hdf_set_valuef(bignode, "%s.tomonth=12", key);
        hdf_set_valuef(bignode, "%s.total=234", key);

        if (i % 10000 == 0) printf("%d\n", i);
    }

    //hdf_dump(bignode, NULL);

    printf("child num %d\n", mcs_get_child_num(bignode, NULL));

    int count = 0;

    mtimer_start();

    HDF *cnode = hdf_obj_child(bignode);
    while (cnode) {
        char *name = hdf_obj_name(cnode);

        if (mcs_get_int_valuef(bignode, 0, "%s.today", name) != 10) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.toweek", name) != 11) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.tomonth", name) != 12) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.total", name) != 234) printf("error\n");

        count++;

        cnode = hdf_obj_next(cnode);
    }

    mtimer_stop("get time");

    printf("get child count %d\n", count);

    hdf_destroy(&bignode);

    return 0;
}
Exemple #20
0
void mjson_asm_objs(HDF *hdf, struct json_object **out)
{
    if (hdf == NULL)
        return;

    struct json_object *jret, *jso;
    char *val, *type;
    bool array = false;

    type = mcs_obj_attr(hdf, "type");
    if (type && !strcmp(type, "array")) {
        array = true;
        jret = json_object_new_array();
    } else {
        jret = json_object_new_object();
    }

    hdf = hdf_obj_child(hdf);

    while (hdf) {
        jso = NULL;
        
        if ((val = hdf_obj_value(hdf)) != NULL) {
            type = mcs_obj_attr(hdf, "type");
            if (type != NULL && !strcmp(type, "int")) {
                jso = json_object_new_int(atoi(val));
            } else {
                jso = json_object_new_string(val);
            }
            if (array)
                json_object_array_add(jret, jso);
            else
                json_object_object_add(jret, hdf_obj_name(hdf), jso);
        }

        if (hdf_obj_child(hdf) != NULL) {
            mjson_asm_objs(hdf, &jso);
            if (array)
                json_object_array_add(jret, jso);
            else
                json_object_object_add(jret, hdf_obj_name(hdf), jso);
        }
        
        hdf = hdf_obj_next(hdf);
    }

    *out = jret;
}
Exemple #21
0
NEOERR* ldml_parse_file(char *dir, char *name, HASH *outhash)
{
    char fname[_POSIX_PATH_MAX], *attrval = NULL;
    HDF *node, *child, *dhdf;
    STRING str;
    NEOERR *err;

    memset(fname, 0x0, sizeof(fname));
    snprintf(fname, sizeof(fname), "%s/%s", dir, name);

    err = hdf_init(&node);
    if (err != STATUS_OK) return nerr_pass(err);

    err = hdf_read_file(node, fname);
    if (err != STATUS_OK) return nerr_pass(err);

    child = hdf_obj_child(node);
    while (child != NULL) {
        mtc_dbg("parse node %s", hdf_obj_name(child));
        string_init(&str);

        attrval = mcs_obj_attr(child, "merge");
        if (attrval) {
            ULIST *list;
            string_array_split(&list, attrval, ",", 10);
            ITERATE_MLIST(list) {
                snprintf(fname, sizeof(fname), "%s/%s",
                         dir, neos_strip((char*)list->items[t_rsv_i]));
                err = hdf_init(&dhdf);
                JUMP_NOK(err, wnext);
                err = hdf_read_file(dhdf, fname);
                JUMP_NOK(err, wnext);
                err = hdf_copy(child, NULL, dhdf);
                JUMP_NOK(err, wnext);
            }
            uListDestroy(&list, ULIST_FREE);
        }

    wnext:
        string_clear(&str);
        child = hdf_obj_next(child);
    }

    err = hash_insert(outhash, (void*)strdup(name), (void*)node);
    JUMP_NOK(err, wnext);

    return STATUS_OK;
}
Exemple #22
0
static PyObject * p_hdf_obj_next (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv;
  HDF *r;

  r = hdf_obj_next (ho->data);
  if (r == NULL)
  {
    rv = Py_None;
    Py_INCREF(rv);
    return rv;
  }
  rv = p_hdf_to_object (r, 0);
  return rv;
}
Exemple #23
0
int  mcs_get_child_num(HDF *hdf, char *name)
{
    HDF *node;
    
    if (!hdf) return 0;

    int count = 0;

    node = hdf_get_child(hdf, name);
    while (node) {
        count++;
        node = hdf_obj_next(node);
    }

    return count;
}
Exemple #24
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;
}
Exemple #25
0
void CGI::TranslateHDF(void *cgi, const std::string &node, Tree *maps)
{
    ::CGI *c = reinterpret_cast< ::CGI *>(cgi);

    HDF *parent = hdf_get_obj(c->hdf, node.c_str());
    if (!parent) {
        return;
    }

    HDF *child = hdf_obj_child(parent);
    while (child) {
        const char *k = hdf_obj_name(child);
        const char *v = hdf_obj_value(child);
        if (k && v) {
            maps->Set(k, v);
        }

        child = hdf_obj_next(child);
    }
}
Exemple #26
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;
}
Exemple #27
0
bool Tree::ParseFromHdfInternal(struct _hdf *hdf)
{
    while (hdf) {
        const char *key = hdf_obj_name(hdf);
        const char *value = hdf_obj_value(hdf);
        if (!value) {
            value = "";
        }

        std::string full_path = GetFullPath(key);
        Tree *child = new Tree(full_path, key, value);
        _children.insert(std::make_pair(key, child));

        HDF *hc = hdf_obj_child(hdf);
        if (!child->ParseFromHdfInternal(hc)) {
            return false;
        }

        hdf = hdf_obj_next(hdf);
    }

    return true;
}
Exemple #28
0
void smsalarm_msg(char *msg)
{
    mdb_conn *db;
    //char content[100];
    NEOERR *err;

    err = mdb_init(&db, SMSA_DB_SN);
    RETURN_NOK(err);

    HDF *node = hdf_get_obj(g_cfg, SMSA_CFG_PATH".leader");
    if (node != NULL) node = hdf_obj_child(node);

    while (node != NULL) {
        //memset(content, 0x0, sizeof(content));
        err = mdb_exec(db, NULL,
                       "INSERT INTO monitor_smssend (smsSendTo, smsContent) VALUES ('%s', '%s')",
                       NULL, hdf_obj_value(node), msg);
        TRACE_NOK(err);
        
        node = hdf_obj_next(node);
    }

    mdb_destroy(db);
}
Exemple #29
0
NEOERR* email_multi_add(HDF *datanode, HASH *evth, char *emailtype)
{
    mevent_t *evt;
    char *mname;
    HDF *child;
    int cnt = 0;
    NEOERR *err;
    
    MCS_NOT_NULLB(datanode, evth);

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

    child = hdf_obj_child(datanode);
    while (child) {
        mname = hdf_get_value(child, "mname", NULL);
        if (mname) {
            /*
             * use cnt instead of mname as hdf key because mname contain '.'
             */
            hdf_set_valuef(evt->hdfsnd, "mto.%d=%s", cnt++, mname);
        }

        child = hdf_obj_next(child);
    }

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

    err = mtpl_InConfigRend_get(evt->hdfsnd, datanode, "email", emailtype, g_datah);
	if (err != STATUS_OK) return nerr_pass(err);

    MEVENT_TRIGGER(evt, NULL, REQ_CMD_AUX_EMAIL_ADD, FLAGS_NONE);

    return STATUS_OK;
}
Exemple #30
0
NEOERR* session_init(CGI *cgi, HASH *dbh, session_t **ses)
{
    session_t *lses;
    HDF *node, *onode;
    char tok[LEN_HDF_KEY], *s;
    NEOERR *err;

    /*
     * follow cgi_parse(), to process _type_object
     */
    s = hdf_get_value(cgi->hdf, PRE_QUERY"._type_object", NULL);
    if (s) {
        ULIST *list;
        string_array_split(&list, s, ",", 50);
        ITERATE_MLIST(list) {
            snprintf(tok, sizeof(tok), "%s.%s",
                     PRE_QUERY, neos_strip((char*)list->items[t_rsv_i]));
            onode = hdf_get_obj(cgi->hdf, tok);
            if (onode) {
                err = mjson_string_to_hdf(onode, NULL, MJSON_EXPORT_NONE);
                TRACE_NOK(err);
            }
        }
        uListDestroy(&list, ULIST_FREE);
    }

    *ses = NULL;

    lses = calloc(1, sizeof(session_t));
    if (!lses) return nerr_raise(NERR_NOMEM, "calloc memory for session_t failure");

    /*
     * mname
     */
    HDF_FETCH_STR(cgi->hdf, PRE_COOKIE".mname", s);
    if (!s) HDF_FETCH_STR(cgi->hdf, PRE_COOKIE".username", s);
    if (s) lses->mname = strdup(s);

    /*
     * province
     */
    HDF_FETCH_STR(cgi->hdf, PRE_COOKIE".province", s);
    hdf_init(&lses->province);
    if (s) {
        neos_unescape((UINT8*)s, strlen(s), '%');
        hdf_set_value(lses->province, NULL, s);
        mjson_export_to_hdf(lses->province, NULL, MJSON_EXPORT_NONE, false);
    }

    /*
     * city
     */
    HDF_FETCH_STR(cgi->hdf, PRE_COOKIE".city", s);
    hdf_init(&lses->city);
    if (s) {
        neos_unescape((UINT8*)s, strlen(s), '%');
        hdf_set_value(lses->city, NULL, s);
        mjson_export_to_hdf(lses->city, NULL, MJSON_EXPORT_NONE, false);
    }

    /*
     * browser
     */
    HDF_FETCH_STR(cgi->hdf, PRE_HTTP".UserAgent", s);
    if (s) {
        mstr_repchr(s, ' ', '\0');
        for (int i = 0; i < m_browsers_size; i++) {
            if (!strncasecmp(s, m_browsers[i], strlen(m_browsers[i]))) {
                lses->browser = i;
                break;
            }
        }
        s = strchr(s, '/');
        if (s) lses->bversion = strtof(s+1, NULL);
    }

    /*
     * reqtype
     */
    lses->reqtype = CGI_REQ_HTML;
    char *uri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, NULL);
    if (!uri) {
        uri = "terminal";
        lses->reqtype = CGI_REQ_TERMINAL;
    }
    mstr_repchr(uri, '/', '_');
    uri = mstr_strip(uri, '_');
    if (!strncmp(uri, "json_", 5)) {
        uri = uri+5;
        lses->reqtype = CGI_REQ_AJAX;
    } else if (!strncmp(uri, "image_", 6)) {
        uri = uri+6;
        lses->reqtype = CGI_REQ_IMAGE;
    }

    /*
     * dataer, render
     */
    switch (http_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);

    /*
     * tm_cache_browser
     */
    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);
    }

    /*
     * DONE
     */
    *ses = lses;

    return STATUS_OK;
}