示例#1
0
文件: neo_hdf.c 项目: bigclean/moc
/* 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);
}
示例#2
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;
}
示例#3
0
文件: ltpl.c 项目: adderly/cmoon
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);
}
示例#4
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;
}
/* 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);
}
示例#6
0
文件: j_neo_util.c 项目: bigclean/moc
JNIEXPORT jint JNICALL Java_org_clearsilver_HDF__1getChild(
    JNIEnv *env, jclass objClass, jint hdf_obj_ptr, jstring j_hdf_path) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  HDF *obj_hdf = NULL;
  const char *hdf_path;

  hdf_path = (*env)->GetStringUTFChars(env, j_hdf_path, 0);
  obj_hdf = hdf_get_child(hdf, (char*)hdf_path);
  (*env)->ReleaseStringUTFChars(env, j_hdf_path, hdf_path);
  return (jint)obj_hdf;
}
示例#7
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 & 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));
}
示例#8
0
文件: mevent.c 项目: bigml/mevent
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;
}
示例#9
0
文件: mcs.c 项目: pombredanne/cmoon
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;
}
示例#10
0
文件: mcs.c 项目: pombredanne/cmoon
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;
}
示例#11
0
static PyObject * p_hdf_get_child (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv;
  char *name;
  HDF *r;

  if (!PyArg_ParseTuple(args, "s:getChild(name)", &name))
    return NULL;

  r = hdf_get_child (ho->data, name);
  if (r == NULL)
  {
    rv = Py_None;
    Py_INCREF(rv);
    return rv;
  }
  rv = p_hdf_to_object (r, 0);
  return rv;
}
示例#12
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;
}
示例#13
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;
}
示例#14
0
NEOERR * rcfs_save (const char *path, const char *data, const char *user, 
                    const char *log)
{
  NEOERR *err;
  HDF *meta = NULL, *vers;
  char fpath[_POSIX_PATH_MAX];
  char buf[256];
  int version = 0;
  int fd;
  int lock;
  int x, l, w;

  err = rcfs_lock (path, &lock);
  if (err) return nerr_pass (err);
  do
  {
    err = rcfs_meta_load (path, &meta);
    if (err && nerr_handle (&err, NERR_NOT_FOUND))
    {
      /* new file! */
      err = hdf_init (&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;
    }

    /* new version */
    version++;
    snprintf (fpath, sizeof (fpath), "%s,%d", path, version);
    fd = open (fpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
    if (fd == -1)
    {
      err = nerr_raise_errno (NERR_IO, "Unable to create file %s", fpath);
      break;
    }
    l = strlen(data);
    w = write (fd, data, l);
    if (w != l)
    {
      err = nerr_raise_errno (NERR_IO, "Unable to write file %s", fpath);
      close (fd);
      break;
    }
    close (fd);
    snprintf (buf, sizeof(buf), "Versions.%d.Log", version);
    err = hdf_set_value (meta, buf, log);
    if (err) break;
    snprintf (buf, sizeof(buf), "Versions.%d.User", version);
    err = hdf_set_value (meta, buf, user);
    if (err) break;
    snprintf (buf, sizeof(buf), "Versions.%d.Date", version);
    err = hdf_set_int_value (meta, buf, ne_timef());
    if (err) break;
    err = _meta_save (path, meta);
  } while (0);

  rcfs_unlock (lock);
  hdf_destroy (&meta);
  return nerr_pass (err);
}