void ChangeDirThread::run() { if (!m_pUser) { gcException gce(ERR_NULLHANDLE, "User Core is null!"); onErrorEvent(gce); onCompleteEvent(); return; } UTIL::FS::recMakeFolder(m_szDest); if (!UTIL::FS::isValidFolder(m_szDest)) { gcException gce(ERR_BADPATH, "Could not create destination folder"); onErrorEvent(gce); onCompleteEvent(); return; } FileList vFileList; updateDb(vFileList); copyFiles(vFileList); if (!m_bStopped) { m_bCompleted = true; } onCompleteEvent(); }
void testUpdateDbNull(CuTest *tc) { // Check that nothing is added to the d/b if we pass in a NULL list int rowsBefore = getDataRowCount(); updateDb(1, NULL); int rowsAfter = getDataRowCount(); CuAssertIntEquals(tc, rowsBefore, rowsAfter); }
void DatabaseData::checkDbLogin() { QFileInfo info(QDir::homePath() + "/.booker/db"); uint lm = info.lastModified().toTime_t(); if(lm == dbFileLastMod) return; else dbFileLastMod = lm; Cryptor cryptorOfficeOnly(pwOffice,true); QFile file(QDir::homePath() + "/.booker/db"); file.open(QIODevice::ReadOnly); QTextStream in(&file); QString line = in.readAll(); QCA::SecureArray all_dbcred = cryptorOfficeOnly.decrypt(line.toLatin1()); SaverDbCred s; // The data is stored in the form: // host=****** // db=****** // db_backup=****** // uname=****** // pw=****** QStringList db_cred = QString::fromLatin1(all_dbcred.data()).split("\n"); if(db_cred.length() != 5) { allErr->catchError("read db_login from file parameter missmatch","cryptdata checkDbLogin"); return; } for(int i = 0; i < db_cred.length(); ++i) { if(db_cred.at(i).startsWith("host=")) s.host = QCA::SecureArray(QString(db_cred.at(i)).remove(0,5).toLatin1()); if(db_cred.at(i).startsWith("db=")) s.database = QCA::SecureArray(QString(db_cred.at(i)).remove(0,3).toLatin1()); if(db_cred.at(i).startsWith("db_backup=")) s.databaseBackup = QCA::SecureArray(QString(db_cred.at(i)).remove(0,10).toLatin1()); if(db_cred.at(i).startsWith("uname=")) s.username = QCA::SecureArray(QString(db_cred.at(i)).remove(0,6).toLatin1()); if(db_cred.at(i).startsWith("pw=")) s.password = QCA::SecureArray(QString(db_cred.at(i)).remove(0,3).toLatin1()); } db_cred.clear(); if(dbLogin.host != s.host || dbLogin.database != s.database || dbLogin.databaseBackup != s.databaseBackup || dbLogin.username != s.username || dbLogin.password != s.password) { dbLogin = s; updateDb(); } }
static int writeUnwrittenDiffs(){ int status = updateDb(POLL_INTERVAL, unwrittenDiffs); logData(unwrittenDiffs); freeData(unwrittenDiffs); unwrittenDiffs = NULL; return status; }
void testUpdateDbMultiple(CuTest *tc) { // Check that the correct number of rows are added when we pass in multiple structs int rowsBefore = getDataRowCount(); struct Data data3 = { 3, 3, 5, 1, "eth0", "", NULL}; struct Data data2 = { 2, 2, 5, 1, "eth1", "", &data3}; struct Data data1 = { 1, 1, 5, 1, "eth2", "", &data2}; updateDb(1,&data1); int rowsAfter = getDataRowCount(); CuAssertIntEquals(tc, rowsBefore + 3, rowsAfter); }
LoginSocket::LoginSocket(const char* listen_address, uint32 port) : ListenSocket(listen_address, port) { updateDb(); _social_net[SocialNetDesc::VK].handler = &LoginSocket::vkReq; _social_net[SocialNetDesc::OK].handler = &LoginSocket::okReq; _social_net[SocialNetDesc::MM].handler = &LoginSocket::mmReq; _social_net[SocialNetDesc::FB].handler = &LoginSocket::fbReq; uint32 num_threads = iServer->getNumWorkerThreads(); for (uint32 i = 0; i < num_threads; ++i) { iThreadCore->startThread(new LoginSocketThread(this)); } #ifdef DEBUG iThreadCore->startThread(new DebugUpdate(this)); #endif }
int main(){ printf("Serwer uruchomiony pomyslnie!\n"); buf = malloc(sizeof(struct mybuf)); stolik = malloc(TBLS * sizeof(struct stoliki)); gracz = malloc(MAX_PLYRS * sizeof(struct gracze)); czyscPoczatek(gracz, stolik); int k; for(k=0;k<TBLS;k++){ stolik[k].zajete=0; } for(k=0;k<MAX_PLYRS;k++){ gracz[k].stolik=0; } int N = MAX_PLYRS; int msgSend = msgget(1234, IPC_CREAT|0600); if(msgSend==-1){ perror("Utworzenie kol. kom. wych."); exit(1); } int msgRcv = msgget(4321, IPC_CREAT|0600); if(msgRcv==-1){ perror("Utworzenie kol. kom. przych."); exit(1); } int quit=0; while(1) { //dodawanie uzytkownika do tymczasowej bazy danych if(msgrcv(msgRcv, buf, (sizeof(struct mybuf)-sizeof(long)), LOGIN ,IPC_NOWAIT) != -1){ //dodawanie graczy; IPC_NOWAIT sprawia ze nie nie ma zawiechy na komunikat buf->mtype = P_INFO; if(liczG < N){ int pom = getSize(buf->val); if(pom>30){ printf("%s ma wiecej niz 30 znakow\n"); clearTab(buf->val, MAX); strcpy(buf->val, "Login ma miec max 30 znakow!\n"); } else{ strcpy(gracz[liczG].login, buf->val); gracz[liczG].stolik = 0; printf("%s dopisany do bazy banych\n", buf->val); liczG++; clearTab(buf->val, MAX); strcpy(buf->val, "Witamy na serwerze!\n"); if(liczS == 0) strcat(buf->val, "Nie ma jeszcze stolikow, jezeli chcesz go utworzyc wpisz \"nowy\"\n"); else{ int i = 0; for(i;i<liczS;i++){ char str[3]; strcat(buf->val, "Stolik "); if((i+1)<10)strcat(buf->val, "0"); sprintf(str, "%d", (i+1)); strcat(buf->val, str); strcat(buf->val, ":\tzajete "); sprintf(str, "%d", stolik[i].zajete); strcat(buf->val, str); strcat(buf->val, "\n"); } } } if(msgsnd(msgSend, buf, (sizeof(struct mybuf)-sizeof(long)), 0) == -1){ perror("Wyslanie odp na login"); exit(1); } usleep(10); } else{ printf("Nie ma juz miejsca na serwerze dla %s.\n", buf->val); clearTab(buf->val, MAX); strcpy(buf->val, "Serwer zapelniony. Przepraszamy.\n"); buf->nr = -1; if(msgsnd(msgSend, buf, (sizeof(struct mybuf)-sizeof(long)), 0) == -1){ perror("Wyslanie odp na login"); } } } //wykonywanie komend else if(msgrcv(msgRcv, buf, (sizeof(struct mybuf)-sizeof(long)), CMD, IPC_NOWAIT) != -1){ printf("Wykonuje polecenie:%s\n", buf->val); buf->mtype = INFO; //wyslanie info o statusie serwera (stanie pokoi) if(checkToN(buf->val, "ping", 4)==1){ updateDb(gracz, stolik, msgSend); clearTab(buf->val, MAX); strcat(buf->val, "Dolacz/stworz nowy pokoj"); int i = 0; for(i;i<liczS;i++){ char str[3]; strcat(buf->val, "\nStolik "); if((i+1)<10)strcat(buf->val, "0"); sprintf(str, "%d", (i+1)); strcat(buf->val, str); strcat(buf->val, ":\tzajete "); sprintf(str, "%d", stolik[i].zajete); strcat(buf->val, str); strcat(buf->val, "\n"); buf->st=0; } } //tworzenie nowego pokoju else if(checkToN(buf->val, "nowy", 4)==1){ char* tmp = malloc(sizeof(char) * 30); copyFromPoint(tmp, buf->val, 6, 36); printf("\nLogin:%s\n",tmp); int id = getId(gracz, liczG, tmp); if(gracz[id].stolik != 0){ printf("Operacja niedozwolona\n"); clearTab(buf->val,MAX); strcpy(buf->val,"Nie mozesz utworzyc nowego pokoju bedac juz w jednym!"); } else{ if(liczS<TBLS){ if(id==-1){ printf("Nie znaleziono %s w bazie danych\n",tmp); clearTab(buf->val, MAX); strcat(buf->val,"Nie ma cie w bazie danych, zaloguj sie ponownie."); } else{ stolik[liczS].zajete = 1; stolik[liczS].gracze[0] = tmp; liczS++; printf("nowy Id: %d\n",id+1); gracz[id].stolik = liczS; clearTab(buf->val, MAX); if(liczS<10){ strcpy(buf->val,"Utworzono pokoj nr 0"); } else{ strcpy(buf->val, "Utworzono pokoj nr "); } char str[3]; sprintf(str, "%d", (liczS)); strcat(buf->val, str); strcat(buf->val, " i dolaczono do niego."); buf->st=liczS; } } else{ clearTab(buf->val,MAX); strcpy(buf->val, "Istnieje juz maksymalna liczba pokoi!"); } } free(tmp); } //dolaczanie do istniejacego pokoju else if(checkToN(buf->val, "dolacz ", 7)==1){ char* tmp = malloc(sizeof(char) * 30); copyFromPoint(tmp, buf->val, 7, 10); //wyciecie numeru pokoju int st = atoi(tmp); printf("Pokoj %d\n", st); if(liczS<st){ printf("Nie istnieje pokoj %s\n", tmp); clearTab(buf->val, MAX); strcpy(buf->val, "Nie istnieje taki pokoj"); } else{ if(stolik[st-1].zajete==3){ printf("Pokoj %d jest zajety\n", st); clearTab(buf->val, MAX); strcpy(buf->val, "Ten pokoj jest juz zapelniony"); } else{ copyFromPoint(tmp, buf->val, 11, 42); printf("Login:%s\n",tmp); int id = getId(gracz, liczG, tmp); if(id==-1)printf("Nie znaleziono %s w bazie danych\n",tmp); else{ printf("Id: %d\n",id+1); gracz[id].stolik = st; stolik[st-1].zajete++; clearTab(buf->val,MAX); if(st<10){ strcpy(buf->val,"Dolaczono do pokoju nr 0"); } else{ strcpy(buf->val, "Dolaczono do pokoju nr "); } int pom=0; char str[11]; sprintf(str, "%d", (st)); strcat(buf->val, str); buf->st=st; printf("Status pokoju %d\n", st); strcpy(buf->val, "Gracze w twoim pokoju"); clearTab(str, 11); sprintf(str, "(%d):\n", stolik[st-1].zajete); strcat(buf->val, str); while(pom<stolik[st-1].zajete){ strcat(buf->val, stolik[st-1].gracze[pom++]); strcat(buf->val, "\n"); } } } } free(tmp); } //wychodzenie z aktualnego pokoju else if(checkToN(buf->val, "wyjdz", 5)==1){ char* tmp = malloc(sizeof(char) * 30); copyFromPoint(tmp, buf->val, 7, 37); printf("\nLogin:%s\n",tmp); int id = getId(gracz, liczG, tmp); if(id==-1) printf("Nie znaleziono %s w bazie danych\n",tmp); else{ int stol = gracz[id].stolik; gracz[id].stolik = 0; stolik[stol-1].zajete--; updateDb(gracz, stolik, msgSend); clearTab(buf->val, MAX); printf("Wychodze z pokoju\n"); int i = 0; for(i;i<liczS;i++){ char str[3]; strcat(buf->val, "Stolik "); if((i+1)<10)strcat(buf->val, "0"); sprintf(str, "%d", (i+1)); strcat(buf->val, str); strcat(buf->val, ":\tzajete "); sprintf(str, "%d", stolik[i].zajete); strcat(buf->val, str); strcat(buf->val, "\n"); buf->st=0; } } printf("Id: %d\n",id+1); free(tmp); } else if(checkToN(buf->val, "status", 6)==1){ char* tmp = malloc(sizeof(char) * 30); copyFromPoint(tmp, buf->val, 7, 37); printf("\nLogin:%s\n",tmp); int id = getId(gracz, liczG, tmp); if(id==-1) printf("Nie znaleziono %s w bazie danych\n",tmp); else{ int stol = gracz[id].stolik; clearTab(buf->val, MAX); updateDb(gracz, stolik, msgSend); if(stol>0){ int pom=0; printf("Status pokoju %d\n", stol); strcpy(buf->val, "Gracze w twoim pokoju"); char str[11]; sprintf(str, "(%d):\n", stolik[stol-1].zajete); strcat(buf->val, str); while(pom<stolik[stol-1].zajete){ strcat(buf->val, stolik[stol-1].gracze[pom++]); strcat(buf->val, "\n"); } } else{ strcpy(buf->val, "Jestes w lobby, przejdz do jednego z pokojow (np. \"dolacz 01\")\n"); buf->st=0; } } free(tmp); } else if(checkToN(buf->val, "shutdown", 8)==1){ char* tmp = malloc(sizeof(char) * 30); copyFromPoint(tmp, buf->val, 10, 37); printf("\nLogin:%s\n",tmp); int id = getId(gracz, liczG, tmp); if(id==-1) printf("Nie znaleziono %s w bazie danych\n",tmp); clearTab(buf->val, MAX); if(checkToN(tmp, "serv_admin", 10)==1){ strcat(buf->val, "Koncze dzialanie serwera"); printf("WYLACZAM SERWER(rozpoczete gry bd przesylac komunikaty, az sie nie skoncza)\n"); if(msgsnd(msgSend, buf, (sizeof(struct mybuf)-sizeof(long)), 0) == -1){ perror("Wyslanie odp na komende"); } clearTab(buf->val, MAX); buf->st=-1; strcat(buf->val,"SERWER ZOSTAL WYLACZONY!!!"); int pl=liczG-1; while(pl>0){ if(msgsnd(msgSend, buf, (sizeof(struct mybuf)-sizeof(long)), 0) == -1){ perror("Wyslanie odp na komende"); } pl--; } //zwalnianie struktur przed zakonczeniem free(buf); free(stolik); free(gracze); exit(0); } else{ strcat(buf->val, "Nie posiadasz uprawnien administratora!"); } } else{ printf("NIE MA TAKIEJ KOMENDY!\n"); clearTab(buf->val, MAX); strcpy(buf->val, "NIE MA TAKIEJ KOMENDY!"); } if(msgsnd(msgSend, buf, (sizeof(struct mybuf)-sizeof(long)), 0) == -1){ perror("Wyslanie odp na komende"); } updateDb(gracz, stolik, msgSend); } } return 0; }
int main(int argc, char *argv[]){ if (argc < 2){ puts("Usage: db [FILE]"); return -1; } Node list; list = readDatabase(argv[1]); puts("Welcome to"); puts(" ____ ____ "); puts("/\\ _`\\ /\\ _`\\ "); puts("\\ \\ \\/\\ \\ \\ \\L\\ \\ "); puts(" \\ \\ \\ \\ \\ \\ _ <\\ "); puts(" \\ \\ \\_\\ \\ \\ \\L\\ \\ "); puts(" \\ \\____/\\ \\____/ "); puts(" \\/___/ \\/___/ "); puts(""); // Main loop int choice = -1; while(choice != 0) { puts("Please choose an operation"); puts("1. Query a key"); puts("2. Update an entry"); puts("3. New entry"); puts("4. Remove entry"); puts("5. Print database"); puts("0. Exit database"); printf("? "); scanf("%d", &choice); while(getchar() != '\n'); // Clear stdin //int found; // Node cursor; char buffer[128]; switch(choice){ case 1: //query queryDb(list, buffer); break; case 2: //update updateDb(list, buffer); break; case 3: //insert list = insertDb(list, buffer, buffer, 1); break; case 4: // Delete list = deleteDb(list, buffer); break; case 5: //print printDb(list); break; case 0: //Fel - prova igen // Exit puts("Good bye!"); break; default: // Please try again puts("Could not parse choice! Please try again"); } puts(""); } return 0; }