Esempio n. 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);
    }
}
Esempio n. 2
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);
}
Esempio n. 3
0
File: ltpl.c Progetto: 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);
}
Esempio n. 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;
}
Esempio n. 5
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;
}
Esempio n. 6
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);
        }
    }
}
Esempio n. 7
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;
}
Esempio n. 8
0
void mjson_str2hdf(HDF *node, struct json_object *o)
{
    if (!node) return;
    
    char *s = hdf_obj_value(node);
    
    struct json_object *obj;
    struct array_list *list;
    enum json_type type;
    HDF *cnode;
    char tok[64];
    int i;
    
    char *key; struct json_object *val; struct lh_entry *entry;
    
    obj = o;

    if (!obj && s && *s) {
        obj = json_tokener_parse(s);
    }
    if (!obj || obj < 0) return;

    type = json_object_get_type(obj);

    switch (type) {
    case json_type_boolean:
        hdf_set_int_value(node, NULL, json_object_get_boolean(obj));
        return;
    case json_type_int:
        hdf_set_int_value(node, NULL, json_object_get_int(obj));
        return;
    case json_type_double:
        sprintf(tok, "%f", json_object_get_double(obj));
        hdf_set_value(node, NULL, tok);
        return;
    case json_type_string:
        hdf_set_value(node, NULL, json_object_get_string(obj));
        return;
    case json_type_array:
        list = json_object_get_array(obj);
        for (i = 0; i < list->length; i++) {
            sprintf(tok, "%d", i);
            hdf_get_node(node, tok, &cnode);
            mjson_str2hdf(cnode, (struct json_object*)list->array[i]);
        }
        return;
    case json_type_object:
        for(entry = json_object_get_object(obj)->head;
            (entry ? (key = (char*)entry->k,
                      val = (struct json_object*)entry->v, entry) : 0);
            entry = entry->next) {
            hdf_get_node(node, key, &cnode);
            mjson_str2hdf(cnode, val);
        }
        return;
    default:
        return;
    }
}
Esempio n. 9
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));
}
Esempio n. 10
0
JNIEXPORT jstring JNICALL Java_org_clearsilver_HDF__1objValue(
    JNIEnv *env, jclass objClass, jint hdf_obj_ptr) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  char *name;
  jstring retval = NULL;

  name = hdf_obj_value(hdf);
  if (name != NULL) {
    retval =  (*env)->NewStringUTF(env, name);
  }
  return retval;
}
Esempio n. 11
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;
}
Esempio n. 12
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;
}
Esempio n. 13
0
static PyObject * p_hdf_obj_value (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv;
  char *r;

  r = hdf_obj_value (ho->data);
  if (r == NULL)
  {
    rv = Py_None;
    Py_INCREF(rv);
    return rv;
  }
  rv = Py_BuildValue ("s", r);
  return rv;
}
Esempio n. 14
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);
    }
}
Esempio n. 15
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;
}
Esempio n. 16
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);
}
Esempio n. 17
0
const char *Hdf::configGet(const char *defValue /* = NULL */) const {
  HDF *hdf = getRaw();
  const char *v = hdf_obj_value(hdf);
  hdf_set_visited(hdf, 1);
  return v ? v : defValue;
}
Esempio n. 18
0
static int mevent_start_driver(struct mevent *evt, struct event_driver *d,
                               void *lib, int num_thread, HDF *matenode)
{
    if (evt == NULL || evt->table == NULL || d == NULL) return 0;

    struct event_entry *e = d->init_driver();
    if (e == NULL) return 0;

    num_thread = num_thread < 0 ? 1 : num_thread;
    if (num_thread > MAX_THREAD_NUM) {
        wlog("plugin %s thread number %d too large, set to default max number %d",
             e->name, num_thread, MAX_THREAD_NUM);
        mtc_warn("plugin %s thread number %d too large, set to default max number %d",
                 e->name, num_thread, MAX_THREAD_NUM);
        num_thread = MAX_THREAD_NUM;
    }

    e->num_thread = num_thread;
    e->cur_thread = 0;

    for (int i = 0; i < num_thread; i++) {
        e->op_queue[i] = queue_create();
        e->op_thread[i] = malloc(sizeof(pthread_t));
        pthread_create(e->op_thread[i], NULL, mevent_start_base_entry, (void*)e);
        sleep(1);
        e->cur_thread++;
    }

    e->cur_thread = 0;

    HDF *cnode = hdf_obj_child(matenode);
    char *dle;
    for (int i = 0; cnode && i < MAX_THREAD_NUM; cnode = hdf_obj_next(cnode)) {
        void* (*mate_func)(void *arg);

        mate_func = dlsym(lib, hdf_obj_value(cnode));
        if ((dle = dlerror()) != NULL) {
            wlog("unable to find %s %s", hdf_obj_value(cnode), dle);
            mtc_err("unable to find %s %s", hdf_obj_value(cnode), dle);
            continue;
        }

        e->mt_thread[i] = malloc(sizeof(pthread_t));
        pthread_create(e->mt_thread[i], NULL, mate_func, (void*)e);
        i++;
    }

    uint32_t h;
    struct event_chain *c;
    h = hash(e->name, e->ksize) % evt->hashlen;
    c = evt->table + h;

    if (c->len == 0) {
        c->first = e;
        c->last = e;
        c->len = 1;
    } else if (c->len <= evt->chainlen) {
        e->next = c->first;
        c->first->prev = e;
        c->first = e;
        c->len += 1;
    } else {
        wlog("unbelieveable, you have more than %d plugins, stop it %s",
             evt->chainlen, e->name);
        mtc_warn("unbelieveable, you have more than %ld plugins, stop it %s",
                 evt->chainlen, e->name);

        mevent_stop_driver(e);
        return 0;
    }

    return 1;
}