static void div_cbk(char *s, size_t len) { char tok[1024]; snprintf(tok, len+1, s); mtc_foo("%s", tok); }
int main(int argc, char **argv, char **envp) { char *bm = NULL; NEOERR *err; int cnt = 0; char *s = argv[1]; mtc_init("div", 7); #if 0 err = ediv_init_from_file(&bm, "/home/bigml/web/moon/eii/data/dict.txt", &cnt); DIE_NOK_MTL(err); mtc_foo("%u words seted\n", cnt); //mtc_foo("%u distinct word\n", ediv_word_distinct(bm)); ediv_word_split(bm, s, strlen(s), NULL, div_cbk, EDIV_SOPT_ONLY_MAXMATCH | EDIV_SOPT_SKIP_NUTF); free(bm); #endif return 0; }
int main(int argc, char **argv, char **envp) { struct json_object *jso; HDF *node; bson *doc; NEOERR *err; mtc_init("hdftest"); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { hdf_init(&node); //err = mjson_string_to_hdf(node, bdatam); OUTPUT_NOK(err); if (VERBERSE) hdf_dump(node, NULL); hdf_destroy(&node); } mtimer_stop("json => hdf"); mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { doc = mbson_new_from_string(bdatam, true); if (!doc) printf("bson error"); if (VERBERSE) printf("%s\n", mbson_string(doc)); bson_free(doc); } mtimer_stop("json => bson"); mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); hdf_init(&node); hdf_set_value(node, NULL, bdatam); //err = mjson_string_to_hdf(node, bdatam); OUTPUT_NOK(err); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { err = mjson_import_from_hdf(node, &jso); OUTPUT_NOK(err); if (VERBERSE) printf("%s\n", json_object_to_json_string(jso)); json_object_put(jso); } mtimer_stop("hdf => json"); mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { err = mbson_import_from_hdf(node, &doc, true); OUTPUT_NOK(err); if (VERBERSE) printf("%s\n", mbson_string(doc)); bson_free(doc); } mtimer_stop("hdf => bson"); mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); doc = mbson_new_from_string(bdatam, true); if (!doc) printf("bson error"); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { char *s = mbson_string(doc); if (!s) printf("bson->string error"); if (VERBERSE) printf("%s\n", s); free(s); } mtimer_stop("bson => json"); mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); mtimer_start(); for (int i = 0; i < NUM_TOTAL_TEST; i++) { hdf_init(&node); //err = mbson_export_to_hdf(node, doc, false, false); OUTPUT_NOK(err); if (VERBERSE) hdf_dump(node, NULL); hdf_destroy(&node); } mtimer_stop("bson => hdf"); //mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f))); bson_free(doc); return 0; }
NEOERR* oms_users_data_add(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic"); char *aname, *pname, *email; int cost; NEOERR *err; APP_CHECK_ADMIN(); HDF_GET_STR_IDENT(cgi->hdf, PRE_COOKIE".aname", pname); HDF_GET_STR(cgi->hdf, PRE_QUERY".aname", aname); HDF_GET_STR(cgi->hdf, PRE_QUERY".email", email); LEGAL_CK_ANAME(pname); LEGAL_CK_ANAME(aname); LEGAL_CK_EMAIL(email); /* * check */ int state = hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE); if (state <= LCS_ST_FREE) return nerr_raise(LERR_NEEDUP, "%s want to add users %s", pname, aname); else if (state >= LCS_ST_VIP) goto add; /* * chargeback */ cost = hdf_get_int_value(g_cfg, "Cost.account", 0); evt = (mevent_t*)hash_lookup(evth, "bank"); hdf_set_value(evt->hdfsnd, "aname", pname); hdf_set_int_value(evt->hdfsnd, "btype", BANK_OP_ADDACCOUNT); hdf_set_int_value(evt->hdfsnd, "fee", cost); hdf_set_value(evt->hdfsnd, "account", aname); MEVENT_TRIGGER(evt, pname, REQ_CMD_BANK_ADDBILL, FLAGS_SYNC); add: /* * add */ evt = (mevent_t*)hash_lookup(evth, "aic"); hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY)); hdf_set_value(evt->hdfsnd, "pname", pname); hdf_set_value(evt->hdfsnd, "aname", aname); hdf_set_int_value(evt->hdfsnd, "state", hdf_get_int_value(evt->hdfrcv, "state", LCS_ST_FREE)); hdf_set_value(evt->hdfsnd, "masn", aname); if (PROCESS_NOK(mevent_trigger(evt, aname, REQ_CMD_APPNEW, FLAGS_SYNC))) { char *zpa = NULL; hdf_write_string(evt->hdfrcv, &zpa); mtc_foo("add %s failure %d %s", aname, evt->errcode, zpa); SAFE_FREE(zpa); if (state < LCS_ST_VIP) { /* * roll back */ evt = (mevent_t*)hash_lookup(evth, "bank"); hdf_set_value(evt->hdfsnd, "aname", pname); hdf_set_int_value(evt->hdfsnd, "btype", BANK_OP_ROLLBACK); hdf_set_int_value(evt->hdfsnd, "fee", -cost); hdf_set_valuef(evt->hdfsnd, "remark = 客服帐号 %s 创建失败", aname); if (PROCESS_NOK(mevent_trigger(evt, pname, REQ_CMD_BANK_ADDBILL, FLAGS_SYNC))) { /* * ATTENTION we need pay back to customer manually */ hdf_write_string(evt->hdfrcv, &zpa); mtc_foo("rollback %s failure %d %s", aname, evt->errcode, zpa); SAFE_FREE(zpa); } } return nerr_raise(evt->errcode, "add %s failure %d", aname, evt->errcode); } return STATUS_OK; }
void msparse_buf(moc_t *evt, int order, int fd, unsigned char *buf, size_t len, moc_arg *arg) { uint32_t totaltoget = 0; moc_srv *srv; NEOERR *err; if (!evt || !buf) { mtc_err("param null"); return; } /* * validate */ if (evt->nservers < order) { mtc_err("order %d > server %d", order, evt->nservers); return; } srv = &(evt->servers[order]); if (srv->fd != fd) { mtc_err("fd not equal %d %d", srv->fd, fd); return; } /* * copy from process_buf() on server/tcp.c */ if (len >= 4) { totaltoget = * (uint32_t*) buf; totaltoget = ntohl(totaltoget); if (totaltoget > (64 * 1024) || totaltoget <= 8) { mtc_err("message illegal %d", totaltoget); return; } } else totaltoget = 4; if (totaltoget > len) { if (srv->buf == NULL) { srv->buf = malloc(SBSIZE); if (!srv->buf) { mtc_foo("out of memory"); return; } memcpy(srv->buf, buf, len); srv->len = len; } else { srv->len = len; } srv->pktsize = totaltoget; /* need rereceive */ return; } if (totaltoget < len) { srv->excess = len - totaltoget; len = totaltoget; } err = msparse_msg(srv, buf + 4, len - 4, arg); TRACE_NOK(err); if (srv->excess) { memmove(buf, buf + len, srv->excess); srv->len = srv->excess; srv->excess = 0; msparse_buf(evt, order, fd, buf, srv->len, arg); /* need reprocess */ return; } if (srv->buf) { free(srv->buf); srv->buf = NULL; srv->len = 0; srv->pktsize = 0; srv->excess = 0; } return; }