static EventEntry* skeleton_init_driver(void) { struct skeleton_entry *e = calloc(1, sizeof(struct skeleton_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 = skeleton_process_driver; e->base.stop_driver = skeleton_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; } 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 vdie(const char *format, va_list alist) { vwarn(format, alist); mdb_destroy(); exit(1); }
static struct event_entry* aic_init_driver(void) { struct aic_entry *e = calloc(1, sizeof(struct aic_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 = aic_process_driver; e->base.stop_driver = aic_stop_driver; char *dbsn = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL); err = mdb_init(&e->db, dbsn); 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; } return (struct event_entry*)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; }
static void terminate(int status) { (void) mdb_signal_blockall(); mdb_destroy(); exit(status); }
int main() { CGI *cgi; NEOERR *err; int ret; //sleep(20); mtc_init(TC_ROOT"login"); mconfig_parse_file(SITE_CONFIG, &g_cfg); err = cgi_init(&cgi, NULL); DIE_NOK_CGI(err); err = cgi_parse(cgi); DIE_NOK_CGI(err); mdb_conn *conn = NULL; ret = mdb_init(&conn, DB_DSN); mdb_opfinish_json(ret, cgi->hdf, conn); ret = login_get(cgi, conn); mdb_opfinish_json(ret, cgi->hdf, conn); mjson_output_hdf(cgi->hdf, 0); #ifdef DEBUG_HDF hdf_write_file(cgi->hdf, TC_ROOT"hdf.login"); #endif mdb_destroy(conn); cgi_destroy(&cgi); return 0; }
static void skeleton_stop_driver(EventEntry *entry) { struct skeleton_entry *e = (struct skeleton_entry*)entry; /* * e->base.name, e->base will free by mevent_stop_driver() */ mdb_destroy(e->db); cache_free(e->cd); }
static void aic_stop_driver(struct event_entry *entry) { struct aic_entry *e = (struct aic_entry*)entry; /* * e->base.name, e->base will free by mevent_stop_driver() */ mdb_destroy(e->db); cache_free(e->cd); }
static void base_stop_driver(EventEntry *entry) { struct base_entry *e = (struct base_entry*)entry; /* * e->base.name, e->base will free by moc_stop_driver() */ mdb_destroy(e->db); cache_free(e->cd); base_info_destroy(m_base); }
int main(int argc, char **argv, char **envp) { CGI *cgi = NULL; NEOERR *err; mdb_conn *conn = NULL; char *s, *u, *p, *r, *jcbk; mtc_init("test"); mconfig_parse_file(SITE_CONFIG, &g_cfg); if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) { mtc_err("init db error %s", mdb_get_errmsg(conn)); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); return 1; } err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { mtc_err("init cgi error"); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("初始化错误"); return 1; } err = cgi_parse(cgi); if (err != STATUS_OK) { mtc_err("parse cgi error"); hdf_set_value(cgi->hdf, PRE_OUTPUT".errmsg", "初始化出错"); goto finish; } u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL); s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL); if (s && u) { if (user_has_login(conn, u, s)) { hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser"); hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey"); hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "1"); goto finish; } } hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "2"); finish: cgi_display(cgi, F_TPL_TEST); cgi_destroy(&cgi); mdb_destroy(conn); return 0; }
static void city_stop_driver(EventEntry *entry) { struct city_entry *e = (struct city_entry*)entry; /* * e->base.name, e->base will free by mevent_stop_driver() */ mdb_destroy(e->db); cache_free(e->cd); if (ips) { free(ips); ips = NULL; } }
static void ngx_http_tcache_mdb_cleanup(ngx_http_tcache_t *cache) { ngx_mdb_t *mdb; mdb = cache->mdb; if (mdb->path) { ngx_delete_file(mdb->path); } if (mdb && mdb->db) { mdb_destroy(mdb->db); } }
static EventEntry* city_init_driver(void) { struct city_entry *e = calloc(1, sizeof(struct city_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 = city_process_driver; e->base.stop_driver = city_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; } s = hdf_get_value(g_cfg, CONFIG_PATH".ipfile", "QQWry.Dat"); err = ne_load_file(s, (char**)&ips); JUMP_NOK(err, error); ipbgn = b2int(ips, 4); ipend = b2int(ips+4, 4); if (ipbgn < 0 || ipend < 0) { wlog("%s format error", s); goto 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); if (ips) free(ips); free(e); return NULL; }
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); }
int main(int argc, char **argv, char **envp) { CGI *cgi = NULL; NEOERR *err; mdb_conn *conn = NULL; /* skey, user, pass, return jsoncallback*/ char *s, *u, *p, *r, *jcbk; /* keeptime(hours) */ int t; char tm[LEN_TM_GMT]; //sleep(20); mtc_init("login"); mconfig_parse_file(SITE_CONFIG, &g_cfg); mutil_wrap_fcgi(argc, argv, envp); if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) { mtc_err("init db error %s", mdb_get_errmsg(conn)); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); return 1; } #ifndef DROP_FCGI while (FCGI_Accept() >= 0) { #endif /* * cgi init */ err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { mtc_err("init cgi error"); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); goto opfinish; } err = cgi_parse(cgi); if (err != STATUS_OK) { mtc_err("parse cgi error"); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE); goto opfinish; } #if 0 if (mutil_client_attack_cookie(cgi->hdf, "login", 30, 60)) { mtc_err("client attack"); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDREST); goto opfinish; } #endif u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL); s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL); if (s && u) { if (user_has_login(conn, u, s)) { hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser"); hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey"); goto done; } } u = hdf_get_value(cgi->hdf, PRE_QUERY".u", NULL); p = hdf_get_value(cgi->hdf, PRE_QUERY".p", NULL); if (!u || !p) { mtc_err("parameter miss %s %s", u, p); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDINPUT); goto opfinish; } s = user_login_auth(conn, u, p); if (!s) { mtc_err("login error %s %s", u, p); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PASSW); goto opfinish; } cgiwrap_write(P3P_HEADER, strlen(P3P_HEADER)); cgi_cookie_set(cgi, "samuser", u, NULL, SITE_DOMAIN, NULL, 1, 0); cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, NULL, 1, 0); #if 0 t = hdf_get_int_value(cgi->hdf, PRE_QUERY".t", 0); mmisc_getdatetime_gmt(tm, sizeof(tm), "%A, %d-%b-%Y %T GMT", 60*60*t); cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, tm, 1, 0); #endif hdf_set_value(cgi->hdf, PRE_OUTPUT".samuser", u); hdf_set_value(cgi->hdf, PRE_OUTPUT".samkey", s); free(s); done: /* * TODO set samkey, samuser to app's domain * DONE this is done by jsonp */ hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1"); opfinish: if (cgi) { r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL); if (r) { cgi_redirect(cgi, r); } else { jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL); if (jcbk != NULL) { mjson_execute_hdf(cgi->hdf, jcbk, 0); } else { mjson_output_hdf(cgi->hdf, 0); } } #ifdef DEBUG_HDF hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.login"); #endif cgi_destroy(&cgi); } #ifndef DROP_FCGI } /* FCGI_Accept() */ #endif mdb_destroy(conn); return 0; }
int main(int argc, char **argv, char **envp) { CGI *cgi = NULL; NEOERR *err; mdb_conn *conn = NULL; /* skey, user, pass, return jsoncallback*/ char *s, *u, *r, *jcbk; //sleep(20); mtc_init("logout"); mconfig_parse_file(SITE_CONFIG, &g_cfg); mutil_wrap_fcgi(argc, argv, envp); if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) { mtc_err("init db error %s", mdb_get_errmsg(conn)); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); return 1; } #ifndef DROP_FCGI while (FCGI_Accept() >= 0) { #endif /* * cgi init */ err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { mtc_err("init cgi error"); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); goto opfinish; } err = cgi_parse(cgi); if (err != STATUS_OK) { mtc_err("parse cgi error"); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE); goto opfinish; } u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL); s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL); if (s && u) { if (user_has_login(conn, u, s)) { user_logout(conn, u); cgi_cookie_clear(cgi, "samuser", SITE_DOMAIN, NULL); cgi_cookie_clear(cgi, "samkey", SITE_DOMAIN, NULL); hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1"); goto opfinish; } } hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NOTLOGIN); opfinish: if (cgi) { r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL); if (r) { cgi_redirect(cgi, r); } else { jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL); if (jcbk != NULL) { mjson_execute_hdf(cgi->hdf, jcbk, 0); } else { mjson_output_hdf(cgi->hdf, 0); } } #ifdef DEBUG_HDF hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.logout"); #endif cgi_destroy(&cgi); } #ifndef DROP_FCGI } /* FCGI_Accept() */ #endif mdb_destroy(conn); return 0; }