void Settings::deleteServer(int const& index) { QSettings settings("Zakynes Soft", "Web Administrator"); QVector<ServerInfo> serverList = listServer(); QVariant serverCount = 0; serverList.remove(index); settings.beginGroup("general"); serverCount = (settings.value("server_count", 1).toInt()); settings.endGroup(); settings.beginGroup("server_list"); for(int i=0 ; i<serverList.size() ; i++) { ServerInfo server = serverList.at(i); QVariant index = i + 1; QString strIndex = index.toString(); server.index = index.toInt(); settings.setValue("name" + strIndex, server.name); settings.setValue("host" + strIndex, server.host); settings.setValue("index" + strIndex, server.index); settings.setValue("dbName" + strIndex, server.dbName); settings.setValue("user" + strIndex, server.user); settings.setValue("password" + strIndex, server.password); } QString strIndex = serverCount.toString(); settings.remove("name" + strIndex); settings.remove("host" + strIndex); settings.remove("index" + strIndex); settings.remove("dbName" + strIndex); settings.remove("user" + strIndex); settings.remove("password" + strIndex); settings.endGroup(); settings.beginGroup("general"); settings.setValue("server_count", serverList.size()); settings.endGroup(); settings.sync(); }
void processRequest(int socket) { char buf[MAX_BUFFER]; char arg[64]; char *token; char username[32], passwd[32]; int read_size = 0; int len = 0; char command[256]; while ((read_size = recv(socket, &buf[len], (MAX_BUFFER-len), 0)) > 0) { char line[read_size]; strncpy(line, &buf[len], sizeof(line)); len += read_size; line[read_size] = '\0'; printf("Found: %s\n", line); // printf("Line: %s\n", command); if (strncmp(line, "LOGIN:"******": "); token = strtok(NULL, " "); if (token == NULL){ write(socket, "No such command.\n", 42); close(socket); return; } strcpy(username, token); if (token == NULL){ write(socket, "No such command.\n", 42); close(socket); return; } token = strtok(NULL, " "); strcpy(passwd, token); if (userAuthServer(socket, username, passwd) == 0){ char *message = "Invalid Username/Password.\n"; write(socket, message, strlen(message)); close(socket); return; } char * auth = "User Authenticated.\n"; write(socket, auth, strlen(auth)); } sscanf(line, "%s %s", command, arg); if (strncmp(command, "GET", 3) == 0) { printf("GET Request\n"); getServer(socket, arg); } else if(strncmp(command, "LIST", 4) == 0) { printf("LIST Request:\n"); // send(socket, command , strlen(command), 0); listServer(socket, username); } else if(strncmp(command, "PUT", 3) == 0){ printf("PUT Request\n"); putServer(socket, arg); } else if(strncmp(command, "LOGIN", 5) == 0) { } else { printf("No such command: %s\n", command); } } if(read_size == 0) { puts("Client has been disconnected"); fflush(stdout); } else if(read_size == -1) { perror("recv failed"); } return; }