char* user_login_auth(mdb_conn *conn, char *uid, char *pass) { if (!conn || !uid || !pass) return NULL; char *p, *r; int ret, x; mdb_exec(conn, NULL, "SELECT password from account WHERE userid=$1;", "s", uid); if (mdb_get(conn, "s", &p) == MDB_ERR_NONE) { if (!strcmp(p, pass)) { r = calloc(1, LEN_SKEY+1); for (x = 0; x < LEN_SKEY; x++) { r[x] = (char)(65 + neo_rand(90-65)); } r[x] = '\0'; ret = mdb_exec(conn, NULL, "UPDATE account SET skey='$1' WHERE " " userid=$2;", "ss", r, uid); if (ret != MDB_ERR_NONE) { mtc_err("exec failure %s", mdb_get_errmsg(conn)); free(r); return NULL; } return r; } } return NULL; }
NEOERR* lutil_fetch_count(HDF *hdf, mdb_conn *conn, char *table, char *cond) { if (!table || !cond) return nerr_raise(NERR_ASSERT, "paramter null"); char *buf; size_t datalen; int count = 0; NEOERR *err; buf = mmc_getf(&datalen, 0, PRE_MMC_COUNT".%s.%s", table, cond); if (buf == NULL) { err = mdb_exec(conn, NULL, "SELECT count(*) FROM %s WHERE %s;", NULL, table, cond); if (err != STATUS_OK) return nerr_pass(err); err = mdb_get(conn, "s", &buf); if (err != STATUS_OK) return nerr_pass(err); count = atoi(buf); mmc_storef(MMC_OP_SET, (void*)buf, 0, ONE_HOUR, 0, PRE_MMC_COUNT".%s.%s", table, cond); } else { count = atoi(buf); } hdf_set_int_value(hdf, PRE_OUTPUT".ttnum", count); return STATUS_OK; }
bool user_has_login(mdb_conn *conn, char *uid, char *skey) { if (!conn || !uid || !skey) return false; char *s; mdb_exec(conn, NULL, "SELECT skey from account WHERE userid=$1;", "s", uid); if (mdb_get(conn, "s", &s) == MDB_ERR_NONE) { if (!strcmp(s, skey)) return true; } return false; }
static EventEntry* aux_init_driver(void) { struct aux_entry *e = calloc(1, sizeof(struct aux_entry)); if (e == NULL) return NULL; NEOERR *err; e->base.name = (unsigned char*)strdup(PLUGIN_NAME); e->base.ksize = strlen(PLUGIN_NAME); e->base.process_driver = aux_process_driver; e->base.stop_driver = aux_stop_driver; //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term); char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL); err = mdb_init(&e->db, s); JUMP_NOK(err, error); e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0); if (e->cd == NULL) { wlog("init cache failure"); goto error; } err = mdb_exec(e->db, NULL, "SELECT id from memory ORDER BY id DESC LIMIT 1", NULL); JUMP_NOK(err, error); err = mdb_get(e->db, "i", &m_memory_maxid); if (nerr_handle(&err, NERR_NOT_FOUND)) { mtc_err("table memory empty"); wlog("table memory empty"); } JUMP_NOK(err, error); return (EventEntry*)e; error: if (e->base.name) free(e->base.name); if (e->db) mdb_destroy(e->db); if (e->cd) cache_free(e->cd); free(e); return NULL; }
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); }
void user_logout(mdb_conn *conn, char *uid) { if (!conn || !uid) return; mdb_exec(conn, NULL, "UPDATE account set skey='0' WHERE userid=$1", "s", uid); }