int importlegacydb(const char *iface, const char *dirname) { DATA data; snprintf(errorstring, 1024, "Importing data from legacy database \"%s\".", iface); printe(PT_Infoless); if (db_getinterfacecountbyname(iface)) { return 0; } if (readdb(&data, iface, dirname, 0) != 0) { return 0; } if (!db_addinterface(iface)) { return 0; } if (!insertlegacydata(&data, iface)) { return 0; } return 1; }
END_TEST START_TEST(readdb_with_empty_file) { disable_logprints(); cfg.flock = 1; ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("existingdb"), 1); ck_assert_int_eq(readdb("existingdb", TESTDBDIR), -1); }
END_TEST START_TEST(readdb_with_nonexisting_file) { disable_logprints(); cfg.flock = 1; strcpy(data.interface, "none"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(readdb("existingdb", TESTDBDIR), 1); ck_assert_str_eq(data.interface, "existingdb"); ck_assert_str_eq(data.nick, "existingdb"); }
int datalist_cacheget(DSTATE *s) { if (cacheget(s->datalist)==0) { /* try to read data from file if not cached */ if (readdb(s->datalist->data.interface, s->dirname)==0) { /* mark cache as filled on read success and force interface status update */ s->datalist->filled = 1; s->dbhash = 0; } else { return 0; } } return 1; }
END_TEST START_TEST(readdb_with_existing_dbfile_and_max_name_length) { initdb(); disable_logprints(); cfg.flock = 1; strcpy(data.interface, "1234567890123456789012345678901"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb("1234567890123456789012345678901", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("1234567890123456789012345678901", sizeof(DATA)), 1); strcpy(data.interface, "none"); ck_assert_int_eq(readdb("1234567890123456789012345678901", TESTDBDIR), 0); ck_assert_str_eq(data.interface, "1234567890123456789012345678901"); }
int mergedb(char iface[], char dirname[]) { DATA mergedata; char *ifaceptr; if (!strstr(iface, "+")) { return 0; } /* create empty database */ emptydb(&mergedata); strncpy_nt(mergedata.iface.interface, iface, 32); strncpy_nt(mergedata.iface.nick, mergedata.iface.interface, 32); if (debug) printf("iface merge: %s\n", iface); ifaceptr = strtok(iface, "+"); /* merge all databases in given string */ while (ifaceptr != NULL) { if (debug) printf("merging %s:\n", ifaceptr); if (readdb(ifaceptr, dirname)!=0) { printf("Merge \"%s\" failed.\n", mergedata.iface.interface); return 0; } if (!mergewith(&mergedata)) { printf("Merge \"%s\" failed for interface \"%s\".\n", mergedata.iface.interface, ifaceptr); return 0; } ifaceptr = strtok(NULL, "+"); } /* clean possible glitches */ cleanmerged(&mergedata); /* replace active data with merged */ if (memcpy(&data, &mergedata, sizeof(data)) != NULL) { return 1; } else { return 0; } }
void cleartop10(const char *iface, const char *dirname) { int i; if (readdb(iface, dirname)!=0) { exit(EXIT_FAILURE); } for (i=0; i<=9; i++) { data.top10[i].rx=data.top10[i].tx=0; data.top10[i].rxk=data.top10[i].txk=0; data.top10[i].used=0; } writedb(iface, dirname, 0); printf("Top10 cleared for interface \"%s\".\n", data.interface); }
void rebuilddbtotal(const char *iface, const char *dirname) { int i; if (readdb(iface, dirname)!=0) { exit(EXIT_FAILURE); } data.totalrx=data.totaltx=data.totalrxk=data.totaltxk=0; for (i=0; i<=11; i++) { if (data.month[i].used) { addtraffic(&data.totalrx, &data.totalrxk, data.month[i].rx, data.month[i].rxk); addtraffic(&data.totaltx, &data.totaltxk, data.month[i].tx, data.month[i].txk); } } writedb(iface, dirname, 0); printf("Total transfer rebuild completed for interface \"%s\".\n", data.interface); }
END_TEST START_TEST(readdb_with_existing_dbfile_with_rename) { initdb(); disable_logprints(); cfg.flock = 1; strcpy(data.interface, "ethtest"); strcpy(data.nick, "ethtest"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb("ethtest2", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("ethtest2", sizeof(DATA)), 1); strcpy(data.interface, "none"); strcpy(data.nick, "none"); ck_assert_int_eq(readdb("ethtest2", TESTDBDIR), 0); ck_assert_str_eq(data.interface, "ethtest2"); ck_assert_str_eq(data.nick, "ethtest2"); }
int run(){ #ifdef _WIN32 WSADATA globalWSAData; WSAStartup( MAKEWORD(2, 2), &globalWSAData ); #endif functions["ping"].push_back(callbacks::ping); functions["pong"].push_back(callbacks::pong); functions["privmsg"].push_back(callbacks::privmsg); functions["whois"].push_back(callbacks::whois); functions["join"].push_back(callbacks::join); functions["nick"].push_back(callbacks::nick); functions["part"].push_back(callbacks::part); functions["motd"].push_back(callbacks::motd); functions["invite"].push_back(callbacks::invite); functions["ban"].push_back(callbacks::ban); functions["unban"].push_back(callbacks::unban); functions["kick"].push_back(callbacks::kick); functions["mute"].push_back(callbacks::mute); functions["unmute"].push_back(callbacks::unmute); functions["mod"].push_back(callbacks::mod); functions["voice"].push_back(callbacks::voice); functions["star"].push_back(callbacks::star); functions["op"].push_back(callbacks::op); functions["sop"].push_back(callbacks::sop); functions["options"].push_back(callbacks::options); functions["servmute"].push_back(callbacks::servmute); functions["guestpass"].push_back(callbacks::guestpass); functions["servstrip"].push_back(callbacks::servstrip); functions["strip"].push_back(callbacks::strip); functions["servoper"].push_back(callbacks::servoper); functions["servmod"].push_back(callbacks::servmod); functions["servban"].push_back(callbacks::servban); functions["servunban"].push_back(callbacks::servunban); functions["servbanlist"].push_back(callbacks::servbanlist); functions["banlist"].push_back(callbacks::banlist); functions["help"].push_back(callbacks::help); functions["echo"].push_back(callbacks::echo); functions["who"].push_back(callbacks::who); functions["mode"].push_back(callbacks::mode); functions["ignore"].push_back(callbacks::ignore); functions["listen"].push_back(callbacks::listen); functions["ignorelist"].push_back(callbacks::ignorelist); functions["color"].push_back(callbacks::color); functions["away"].push_back(callbacks::away); functions["motdhistory"].push_back(callbacks::motdhistory); functions["topic"].push_back(callbacks::motd); functions["timezone"].push_back(callbacks::timezone); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); DEBUG; user u; u.id = 0; u.access = 0; u.nick = u.name = u.ip = u.color = ""; users.push_back( u ); u.id = 1; u.access = ACCESS_SOP|ACCESS_AOP|ACCESS_HOP|ACCESS_VOP|ACCESS_NONE; u.nick = u.name = servername; u.ip = "Coldstorm"; u.color = "FFFFFF"; u.country = "CS"; users.push_back( u ); frist = users.size(); DEBUG; readdb("database.kdb"); DEBUG; //atexit( onquit ); //atexit( socketcleanup ); DEBUG; guestpasses.push_back("1"); guestpasses.push_back("2"); guestpasses.push_back("3"); guestpasses.push_back("4"); guestpasses.push_back("5"); guestpasses.push_back("6"); DEBUG; call_thread( flushthread, 0 ); call_thread( listenfortcp, 0 ); DEBUG; call_thread( listenforajax, 0 ); DEBUG; char test[100]; DEBUG; gets(test); DEBUG; socketcleanup(); onquit(); return ERROR_NONE; }