lcbio_CTX * lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_EASYPROCS *procs) { lcbio_CTX *ctx = calloc(1, sizeof(*ctx)); ctx->sock = sock; sock->ctx = ctx; ctx->io = sock->io; ctx->data = data; ctx->procs = *procs; ctx->state = ES_ACTIVE; ctx->as_err = lcbio_timer_new(ctx->io, ctx, err_handler); ctx->subsys = "unknown"; rdb_init(&ctx->ior, sock->settings->allocator_factory()); lcbio_ref(sock); if (IOT_IS_EVENT(ctx->io)) { ctx->event = IOT_V0EV(ctx->io).create(IOT_ARG(ctx->io)); ctx->fd = sock->u.fd; } else { ctx->sd = sock->u.sd; } ctx->procs = *procs; ctx->state = ES_ACTIVE; lcb_log(LOGARGS(ctx, DEBUG), CTX_LOGFMT "Pairing with SOCK=%p", CTX_LOGID(ctx), (void*)sock); return ctx; }
double rdb_check_adds_per_second(void) { uint32_t i; rdb_t rdb; clock_t timer; int failures = 0; /* count number of failures */ if (rdb_init(&rdb) != err_status_ok) { printf("rdb_init failed\n"); exit(1); } timer = clock(); for(i=0; i < REPLAY_NUM_TRIALS; i+=3) { if (rdb_check(&rdb, i+2) != err_status_ok) ++failures; if (rdb_add_index(&rdb, i+2) != err_status_ok) ++failures; if (rdb_check(&rdb, i+1) != err_status_ok) ++failures; if (rdb_add_index(&rdb, i+1) != err_status_ok) ++failures; if (rdb_check(&rdb, i) != err_status_ok) ++failures; if (rdb_add_index(&rdb, i) != err_status_ok) ++failures; } timer = clock() - timer; return (double) CLOCKS_PER_SEC * REPLAY_NUM_TRIALS / timer; }
err_status_t test_rdb_db() { rdb_t rdb; uint32_t idx, ircvd; ut_connection utc; err_status_t err; if (rdb_init(&rdb) != err_status_ok) { printf("rdb_init failed\n"); return err_status_init_fail; } /* test sequential insertion */ for (idx=0; idx < num_trials; idx++) { err = rdb_check_add(&rdb, idx); if (err) return err; } /* test for false positives */ for (idx=0; idx < num_trials; idx++) { err = rdb_check_expect_failure(&rdb, idx); if (err) return err; } /* re-initialize */ if (rdb_init(&rdb) != err_status_ok) { printf("rdb_init failed\n"); return err_status_fail; } /* test non-sequential insertion */ ut_init(&utc); for (idx=0; idx < num_trials; idx++) { ircvd = ut_next_index(&utc); err = rdb_check_unordered(&rdb, ircvd); if (err) return err; } return err_status_ok; }
int init_obj(void) { if (initSocket()) return -1; char szFilePath[256] = {0}; char szFileName[256] = {0}; char szLogFilePath[256] = {0}; if (getExePath(szFilePath, szFileName, 256)) return -1; sprintf(szLogFilePath, "%s/%s", szFilePath, "log.dat"); #ifdef _MYDEBUG if (loginit(szLogFilePath, LOG_INFO)) return -1; #else if (loginit(szLogFilePath, LOG_WARNING)) return -1; #endif if (rdb_init()) { logout(LOG_EMERGENCY, "Failed to init protocol", __FILE__, __LINE__); return -1; } if (pushOut_init()) { logout(LOG_ERR, "Failed to init push out", __FILE__, __LINE__); return -1; } if (ptl_init()) { logout(LOG_EMERGENCY, "Failed to init protocol", __FILE__, __LINE__); return -1; } return 0; }
/** * The /os set command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ static int do_set(User * u) { char *option = strtok(NULL, " "); char *setting = strtok(NULL, " "); int index; Channel *c; if (!option) { syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX); } else if (stricmp(option, "LIST") == 0) { index = (allow_ignore ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "IGNORE"); index = (readonly ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "READONLY"); index = (logchan ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "LOGCHAN"); index = (debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "DEBUG"); index = (noexpire ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "NOEXPIRE"); #ifdef USE_MYSQL index = (do_mysql ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF); notice_lang(s_OperServ, u, index, "SQL"); #endif } else if (!setting) { syntax_error(s_OperServ, u, "SET", OPER_SET_SYNTAX); } else if (stricmp(option, "IGNORE") == 0) { if (stricmp(setting, "on") == 0) { allow_ignore = 1; notice_lang(s_OperServ, u, OPER_SET_IGNORE_ON); } else if (stricmp(setting, "off") == 0) { allow_ignore = 0; notice_lang(s_OperServ, u, OPER_SET_IGNORE_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_IGNORE_ERROR); } #ifdef USE_MYSQL } else if (stricmp(option, "SQL") == 0) { if (stricmp(setting, "on") == 0) { if (!MysqlHost) { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED); } else { if (rdb_init()) { notice_lang(s_OperServ, u, OPER_SET_SQL_ON); } else { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_INIT); } } } else if (stricmp(setting, "off") == 0) { if (!MysqlHost) { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR_DISABLED); } else { /* could call rdb_close() but that does nothing - TSL */ do_mysql = 0; notice_lang(s_OperServ, u, OPER_SET_SQL_OFF); } } else { notice_lang(s_OperServ, u, OPER_SET_SQL_ERROR); } #endif } else if (stricmp(option, "READONLY") == 0) { if (stricmp(setting, "on") == 0) { readonly = 1; alog("Read-only mode activated"); close_log(); notice_lang(s_OperServ, u, OPER_SET_READONLY_ON); } else if (stricmp(setting, "off") == 0) { readonly = 0; open_log(); alog("Read-only mode deactivated"); notice_lang(s_OperServ, u, OPER_SET_READONLY_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_READONLY_ERROR); } } else if (stricmp(option, "LOGCHAN") == 0) { /* Unlike the other SET commands where only stricmp is necessary, * we also have to ensure that LogChannel is defined or we can't * send to it. * * -jester */ if (LogChannel && (stricmp(setting, "on") == 0)) { if (ircd->join2msg) { c = findchan(LogChannel); anope_cmd_join(s_GlobalNoticer, LogChannel, c ? c->creation_time : time(NULL)); } logchan = 1; alog("Now sending log messages to %s", LogChannel); notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ON, LogChannel); } else if (LogChannel && (stricmp(setting, "off") == 0)) { alog("No longer sending log messages to a channel"); if (ircd->join2msg) { anope_cmd_part(s_GlobalNoticer, LogChannel, NULL); } logchan = 0; notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_LOGCHAN_ERROR); } /** * Allow the user to turn super admin on/off * * Rob **/ } else if (stricmp(option, "SUPERADMIN") == 0) { if (!SuperAdmin) { notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_NOT_ENABLED); } else if (stricmp(setting, "on") == 0) { u->isSuperAdmin = 1; notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_ON); alog("%s: %s is a SuperAdmin ", s_OperServ, u->nick); anope_cmd_global(s_OperServ, getstring2(NULL, OPER_SUPER_ADMIN_WALL_ON), u->nick); } else if (stricmp(setting, "off") == 0) { u->isSuperAdmin = 0; notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_OFF); alog("%s: %s is no longer a SuperAdmin", s_OperServ, u->nick); anope_cmd_global(s_OperServ, getstring2(NULL, OPER_SUPER_ADMIN_WALL_OFF), u->nick); } else { notice_lang(s_OperServ, u, OPER_SUPER_ADMIN_SYNTAX); } } else if (stricmp(option, "DEBUG") == 0) { if (stricmp(setting, "on") == 0) { debug = 1; alog("Debug mode activated"); notice_lang(s_OperServ, u, OPER_SET_DEBUG_ON); } else if (stricmp(setting, "off") == 0 || (*setting == '0' && atoi(setting) == 0)) { alog("Debug mode deactivated"); debug = 0; notice_lang(s_OperServ, u, OPER_SET_DEBUG_OFF); } else if (isdigit(*setting) && atoi(setting) > 0) { debug = atoi(setting); alog("Debug mode activated (level %d)", debug); notice_lang(s_OperServ, u, OPER_SET_DEBUG_LEVEL, debug); } else { notice_lang(s_OperServ, u, OPER_SET_DEBUG_ERROR); } } else if (stricmp(option, "NOEXPIRE") == 0) { if (stricmp(setting, "ON") == 0) { noexpire = 1; alog("No expire mode activated"); notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ON); } else if (stricmp(setting, "OFF") == 0) { noexpire = 0; alog("No expire mode deactivated"); notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_OFF); } else { notice_lang(s_OperServ, u, OPER_SET_NOEXPIRE_ERROR); } } else { notice_lang(s_OperServ, u, OPER_SET_UNKNOWN_OPTION, option); } return MOD_CONT; }