Пример #1
0
void lerr_opfinish_json(NEOERR *err, HDF *hdf)
{
    if (err == STATUS_OK) {
        hdf_set_value(hdf, PRE_SUCCESS, "1");
        return;
    }
    
    hdf_remove_tree(hdf, PRE_SUCCESS);
    
    char buf[1024], errname[128];
    NEOERR *neede = mcs_err_valid(err);
    if (!neede) neede = err;
    snprintf(buf, sizeof(buf), "%s:%d %s",
             neede->file, neede->lineno,
             _lookup_errname(neede, errname, sizeof(errname)));
    /* set PRE_ERRXXX with the most recently err */
    if (!hdf_get_obj(hdf, PRE_ERRMSG)) {
        hdf_set_value(hdf, PRE_ERRMSG, buf);
    }
    hdf_set_int_value(hdf, PRE_ERRCODE, neede->error);

    STRING str; string_init(&str);
    nerr_error_traceback(err, &str);
    mtc_err("%s", str.buf);
    hdf_set_value(hdf, PRE_ERRTRACE, str.buf);
    nerr_ignore(&err);
    string_clear(&str);
}
Пример #2
0
NEOERR* member_check_login_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *db = hash_lookup(dbh, "main");
    char *mname, *mmsn;
    NEOERR *err;
    
    MCS_NOT_NULLB(cgi->hdf, db);

    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mname", mname);
    HDF_FETCH_STR(cgi->hdf, PRE_QUERY".mmsn", mmsn);
    if (!mname || !mmsn) {
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mname", mname);
        HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".mmsn", mmsn);
    }
    hdf_set_value(cgi->hdf, PRE_RESERVE".mname", mname);

    MDB_QUERY_RAW(db, "member", _COL_MEMBER, "mname=$1", "s", mname);
    err = mdb_set_row(cgi->hdf, db, _COL_MEMBER, PRE_OUTPUT".member", MDB_FLAG_Z);
    if (err != STATUS_OK) return nerr_pass(err);

    char *mmsndb = hdf_get_value(cgi->hdf, PRE_OUTPUT".member.mmsn", NULL);
    if (!mmsndb || strcmp(mmsndb, mmsn)) {
        hdf_remove_tree(cgi->hdf, PRE_OUTPUT".member");
        return nerr_raise(LERR_NOTLOGIN, "msn don't match");
    }
    
    return STATUS_OK;
}
Пример #3
0
Файл: lerr.c Проект: bigml/mgate
void lerr_opfinish_json(NEOERR *err, HDF *hdf)
{
    if (err == STATUS_OK) {
        hdf_set_value(hdf, PRE_SUCCESS, "1");
        mcs_set_int_attr(hdf, PRE_SUCCESS, "type", CNODE_TYPE_INT);
        return;
    }

    hdf_remove_tree(hdf, PRE_SUCCESS);

    NEOERR *neede = mcs_err_valid(err);
    /* set PRE_ERRXXX with the most recently err */
    mcs_set_int_value_with_type(hdf, PRE_ERRCODE, neede->error, CNODE_TYPE_INT);
    if (!hdf_get_obj(hdf, PRE_ERRMSG)) {
        hdf_set_valuef(hdf, "%s=%s:%d %s",
                       PRE_ERRMSG, neede->file, neede->lineno, neede->desc);
    }

    STRING str; string_init(&str);
    nerr_error_traceback(err, &str);
    mtc_err("%s", str.buf);
    hdf_set_value(hdf, PRE_ERRTRACE, str.buf);
    nerr_ignore(&err);
    string_clear(&str);
}
Пример #4
0
NEOERR* mcs_remove_treef(HDF *hdf, char *fmt, ...)
{
    char key[LEN_HDF_KEY];
    va_list ap;

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

    return nerr_pass(hdf_remove_tree(hdf, key));
}
Пример #5
0
CGI::CGI(bool process_body) : _GET(_request_queries)
                            , _POST(_request_posts)
                            , _COOKIE(_request_cookies)
                            , _SERVER(_server_variables)
                            , _REQUEST(_request_all)
                            , _FILES(_uploaded_files)
                            , BODY(this)
                            , _request_handled(false)
                            , _header_sent(false)
                            , _body_sent(false)
                            , _buffered(true)
                            , _status(200)
                            , _cgi_handle(NULL)
{
    void **cgiptr = &_cgi_handle;
    ::CGI * &cgi = *reinterpret_cast< ::CGI **>(cgiptr);
    NEOERR *err;

    TranslateEnvvars(&_server_variables);

    err = cgi_init(&cgi, NULL);
    ThrowIfNeoError(err);

    TranslateHDF(cgi, "Cookie", &_request_cookies);
    TranslateHDF(cgi, "Query",  &_request_queries);

    if (!process_body) {
        return;
    }

    err = cgi_register_parse_cb(cgi, "POST", "*", this, Parser::Parse);
    ThrowIfNeoError(err);

    // Purge Query subtree so GET values are gone.
    err = hdf_remove_tree(cgi->hdf, "Query");
    ThrowIfNeoError(err);

    err = cgi_parse(cgi);
    ThrowIfNeoError(err);

    if (_SERVER["REQUEST_METHOD"].compare("POST") == 0) {
        TranslatePost(cgi, &_request_posts, &_uploaded_files);

    } else if (_SERVER["REQUEST_METHOD"].compare("PUT") == 0) {
        TranslatePut(cgi, &_uploaded_files);
    }

    // Now we have both GET and POST data, POST overwrites GET.
    _request_all = _request_queries;
    _request_all.Merge(_request_posts, true);
}
Пример #6
0
static PyObject * p_hdf_remove_tree (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv;
  char *name;
  NEOERR *err;

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

  err = hdf_remove_tree (ho->data, name);
  if (err) return p_neo_error(err); 

  rv = Py_None;
  Py_INCREF(rv);
  return rv;
}
Пример #7
0
void fdb_opfinish_json(int ret, HDF *hdf, fdb_t *fdb)
{
    char msg[LEN_SM];
    
    if (ret == RET_DBOP_OK) {
        hdf_set_value(hdf, PRE_SUCCESS, "1");
        return;
    }

    hdf_remove_tree(hdf, PRE_SUCCESS);
    get_errmsg(ret, msg);
    hdf_set_value(hdf, PRE_ERRMSG, msg);
    mjson_output_hdf(hdf, 0);
    
    if (fdb != NULL) {
        fdb_free(&fdb);
    }
    /* TODO system resource need free*/
    exit(ret);
}
Пример #8
0
int main(void) {
  HDF *hdf_1, *hdf_2;
  HDF *cur_node,*last_node;

  hdf_init(&hdf_1);

  hdf_read_file(hdf_1,"hdf_copy_test.hdf");
  hdf_dump(hdf_1,NULL);

  cur_node = hdf_get_obj(hdf_1,"Chart");
  last_node = cur_node;

  cur_node = hdf_get_obj(cur_node,"next_stage");
  while (hdf_get_obj(cur_node,"next_stage") && strcmp(hdf_get_value(cur_node,"Bucket.FieldId",""),"QUEUE")) {
    last_node = cur_node;
    cur_node = hdf_get_obj(cur_node,"next_stage");
  }

  if (hdf_get_obj(cur_node,"next_stage")) {
    hdf_copy(hdf_1,"TempHolderPlace",hdf_get_obj(cur_node,"next_stage"));
  }
  ne_warn("Delete tree from node: %s", hdf_obj_name(last_node));
  hdf_remove_tree(last_node,"next_stage");

  hdf_dump(hdf_1,NULL);
  fprintf(stderr,"-----------------\n");


  hdf_copy(last_node,"next_stage",hdf_get_obj(hdf_1,"TempHolderPlace"));
  hdf_dump(hdf_1,NULL);

  /* Test copy and destroy, make sure we actually copy everything and
   * don't reference anything */
  hdf_init(&hdf_2);
  hdf_copy(hdf_2, "", hdf_1);
  hdf_destroy(&hdf_1);
  hdf_dump(hdf_2, NULL);
  hdf_destroy(&hdf_2);

  return 0;
}
Пример #9
0
JNIEXPORT void JNICALL Java_org_clearsilver_HDF__1removeTree(
    JNIEnv *env, jclass objClass,
    jint hdf_obj_ptr, jstring j_hdfname) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  NEOERR *err;
  const char *hdfname;

  if (!j_hdfname) {
    throwNullPointerException(env, "hdfname argument was null");
    return;
  }
  hdfname = (*env)->GetStringUTFChars(env, j_hdfname, 0);
  err = hdf_remove_tree(hdf, hdfname);

  (*env)->ReleaseStringUTFChars(env, j_hdfname, hdfname);

  if (err != STATUS_OK) {
    // Throw an exception
    jNeoErr(env, err);
  }
}
Пример #10
0
NEOERR* member_login_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *db = hash_lookup(dbh, "main");
    char *mname, *msn;
    NEOERR *err;
    
    MCS_NOT_NULLB(cgi->hdf, db);

    HDF_GET_STR(cgi->hdf, PRE_QUERY".mname", mname); 
    HDF_GET_STR(cgi->hdf, PRE_QUERY".msn", msn);

    MDB_QUERY_RAW(db, "member", _COL_MEMBER, "mname=$1", "s", mname);
    err = mdb_set_row(cgi->hdf, db, _COL_MEMBER, PRE_OUTPUT".member", MDB_FLAG_Z);
    if (err != STATUS_OK) return nerr_pass(err);

    char *msndb = hdf_get_value(cgi->hdf, PRE_OUTPUT".member.msn", NULL);
    if (!msndb || strcmp(msndb, msn)) {
        hdf_remove_tree(cgi->hdf, PRE_OUTPUT".member");
        return nerr_raise(LERR_LOGINPSW, "msn incorrct");
    }

    return nerr_pass(member_after_login(cgi, dbh, mname));
}
Пример #11
0
void Hdf::remove(const char *name) const {
  assert(name && *name);
  CheckNeoError(hdf_remove_tree(getRaw(), name));
}
Пример #12
0
/*
 * application logic message, called by msparse_buf()
 */
static NEOERR* msparse_msg(moc_srv *srv, unsigned char *buf, size_t len, moc_arg *arg)
{
    uint32_t id, reply;
    unsigned char *payload;
    size_t psize, rv;

    MOC_NOT_NULLB(arg, arg->evth);
    
    if (!srv || !buf || len < 8) return nerr_raise(NERR_ASSERT, "illegal packet");

    //MSG_DUMP("recv: ", buf, len);

    /* The header is:
     * 4 bytes    ID
     * 4 bytes    Reply Code
     * Variable   Payload
     */
    id = ntohl(* ((uint32_t *) buf));
    reply = ntohl(* ((uint32_t *) buf + 1));

    payload = buf + 8;
    psize = len - 8;

    if (id == 0 && reply == 10000) {
        /*
         * server push
         */
        if (psize < 4) return nerr_raise(NERR_ASSERT, "server pushed empty message");

        struct msqueue_entry *e = msqueue_entry_create();
        if (!e) return nerr_raise(NERR_NOMEM, "alloc msqueue entry");
        
        rv = unpack_hdf(payload + 4, psize - 4, &(e->hdfrcv));
        if (rv <= 0) return nerr_raise(NERR_ASSERT, "server pushed illegal message");

        //TRACE_HDF(e->hdfrcv);

        char *cmd = NULL;
        HDF_ATTR *attr = hdf_get_attr(e->hdfrcv, "_Reserve");
        while (attr != NULL) {
            if (!strcmp(attr->key, "cmd")) cmd = attr->value;
            attr = attr->next;
        }
        if (!cmd) return nerr_raise(NERR_ASSERT, "cmd not supplied");

        e->ename = strdup(srv->evt->ename);
        e->cmd = strdup(cmd);

        mtc_dbg("receive cmd %s", cmd);
        
        hdf_remove_tree(e->hdfrcv, "_Reserve");

        mssync_lock(&arg->callbacksync);
        msqueue_put(arg->callbackqueue, e);
        mssync_unlock(&arg->callbacksync);

        /*
         * notify callback thread
         */
        mssync_signal(&arg->callbacksync);
    } else {
        /*
         * server response
         */
        if (id < g_reqid)
            return nerr_raise(NERR_ASSERT, "id not match %d %d", g_reqid, id);

        if (psize >= 4) {
            mssync_lock(&(arg->mainsync));
            rv = unpack_hdf(payload + 4, psize - 4, &(srv->evt->hdfrcv));
            mssync_unlock(&(arg->mainsync));
            if (rv <= 0)
                return nerr_raise(NERR_ASSERT, "server responsed illegal message");

            //TRACE_HDF(srv->evt->hdfrcv);
        }

        /*
         * notify main thread
         */
        mssync_signal(&(arg->mainsync));
    }
    
    return STATUS_OK;
}