void ServerThread::readyRead() { if(!isInitialized) { initialize(); return; } QDataStream input(s); s->waitForReadyRead(); MessageEnvelop e; try { input >> e; } catch(MessageException e) { qDebug() << "Hackers are strong " << "But I'm stronger"; return; //sendError("Telnet Cannot kill me"); } switch (e.getRequestType()) { case SEND_LOGIN_TO_SERVER: case PING: case OK: return; case REQUEST_CALL_TO_CLIENT_FROM_SERVER: qDebug() << "Connection init"; return requestCall(e.getName()); case REQUEST_CLIENT_LIST_FROM_SERVER: return sendError("The List will be sent M'kay"); case SEND_DENIED_RESPONSE_TO_COMMUNICATION: sendConnectionDenied(); return; case SEND_SUCCESS_RESPONSE_TO_COMMUNICATION: qDebug() << "Connection Granted"; ConnectionGranted(e.getPassword()); return; case SEND_LOGOUT_REQUEST: logout(); return; case END_OF_CALL_TO_CLIENT: case ERROR_SERVER_RESPONSE: return sendError("Only me can communicate on port 666 MUHEHEHE"); default: return sendError("Unrecognized messsage type M'kay"); } }
void ServerThread::registerNewClient(MessageEnvelop &e) { if(database->existsUser(e.getName().toStdString())) { sendError("The Username already exists M'kay, pick another one M'kay"); emit error(this->s->error()); return; } std::ifstream rand("/dev/urandom",std::ios::binary); char * newSalt = new char[8]; rand.read(newSalt, 8); rand.close(); char * corrSalt = getAscii85(newSalt, 8); delete[] newSalt; std::string s(e.getPassword().toStdString()), qCorrSalt(corrSalt); s = s + qCorrSalt; free(corrSalt); unsigned char hash[32]; char *printableHash; sha2((unsigned char *) s.c_str(), s.length(), hash, 0); printableHash = getAscii85((char*) hash, 32); QString pass(printableHash), Qsalt(qCorrSalt.c_str()); try { database->insertUser(e.getName().toStdString(), pass.toStdString(), Qsalt.toStdString()); } catch(SqlConnection::SqlException e) { sendError("The user was not added"); emit error(this->s->error()); return; } QByteArray b; QDataStream outStr(&b, QIODevice::WriteOnly); MessageEnvelop ret(REGISTER_APROOVED); isInitialized = false; outStr << ret; this->s->write(b); }
void ClangCodeModelClientInterface::dispatch(const MessageEnvelop &messageEnvelop) { switch (messageEnvelop.messageType()) { case MessageType::AliveMessage: alive(); break; case MessageType::EchoMessage: echo(messageEnvelop.message<EchoMessage>()); break; case MessageType::CodeCompletedMessage: codeCompleted(messageEnvelop.message<CodeCompletedMessage>()); break; case MessageType::TranslationUnitDoesNotExistMessage: translationUnitDoesNotExist(messageEnvelop.message<TranslationUnitDoesNotExistMessage>()); break; case MessageType::ProjectPartsDoNotExistMessage: projectPartsDoNotExist(messageEnvelop.message<ProjectPartsDoNotExistMessage>()); break; case MessageType::DocumentAnnotationsChangedMessage: documentAnnotationsChanged(messageEnvelop.message<DocumentAnnotationsChangedMessage>()); break; default: qWarning() << "Unknown ClangCodeModelClientMessage"; } }
void ClangCodeModelServerInterface::dispatch(const MessageEnvelop &messageEnvelop) { switch (messageEnvelop.messageType()) { case MessageType::EndMessage: end(); break; case MessageType::RegisterTranslationUnitForEditorMessage: registerTranslationUnitsForEditor(messageEnvelop.message<RegisterTranslationUnitForEditorMessage>()); break; case MessageType::UpdateTranslationUnitsForEditorMessage: updateTranslationUnitsForEditor(messageEnvelop.message<UpdateTranslationUnitsForEditorMessage>()); break; case MessageType::UnregisterTranslationUnitsForEditorMessage: unregisterTranslationUnitsForEditor(messageEnvelop.message<UnregisterTranslationUnitsForEditorMessage>()); break; case MessageType::RegisterProjectPartsForEditorMessage: registerProjectPartsForEditor(messageEnvelop.message<RegisterProjectPartsForEditorMessage>()); break; case MessageType::UnregisterProjectPartsForEditorMessage: unregisterProjectPartsForEditor(messageEnvelop.message<UnregisterProjectPartsForEditorMessage>()); break; case MessageType::RegisterUnsavedFilesForEditorMessage: registerUnsavedFilesForEditor(messageEnvelop.message<RegisterUnsavedFilesForEditorMessage>()); break; case MessageType::UnregisterUnsavedFilesForEditorMessage: unregisterUnsavedFilesForEditor(messageEnvelop.message<UnregisterUnsavedFilesForEditorMessage>()); break; case MessageType::CompleteCodeMessage: completeCode(messageEnvelop.message<CompleteCodeMessage>()); break; case MessageType::RequestDocumentAnnotationsMessage: requestDocumentAnnotations(messageEnvelop.message<RequestDocumentAnnotationsMessage>()); break; case MessageType::RequestReferencesMessage: requestReferences(messageEnvelop.message<RequestReferencesMessage>()); break; case MessageType::RequestFollowSymbolMessage: requestFollowSymbol(messageEnvelop.message<RequestFollowSymbolMessage>()); break; case MessageType::RequestToolTipMessage: requestToolTip(messageEnvelop.message<RequestToolTipMessage>()); break; case MessageType::UpdateVisibleTranslationUnitsMessage: updateVisibleTranslationUnits(messageEnvelop.message<UpdateVisibleTranslationUnitsMessage>()); break; default: qWarning() << "Unknown ClangCodeModelServerMessage"; } }
void PchManagerServerInterface::dispatch(const MessageEnvelop &messageEnvelop) { switch (messageEnvelop.messageType()) { case MessageType::EndMessage: end(); break; case MessageType::UpdateProjectPartsMessage: updateProjectParts(messageEnvelop.message<UpdateProjectPartsMessage>()); break; case MessageType::RemoveProjectPartsMessage: removeProjectParts(messageEnvelop.message<RemoveProjectPartsMessage>()); break; default: qWarning() << "Unknown IpcClientMessage"; } }
QDebug operator<<(QDebug debug, const MessageEnvelop &messageEnvelop) { debug.nospace() << "MessageEnvelop("; switch (messageEnvelop.messageType()) { case MessageType::EndMessage: qDebug() << "EndMessage()"; break; case MessageType::RegisterTranslationUnitForEditorMessage: qDebug() << messageEnvelop.message<RegisterTranslationUnitForEditorMessage>(); break; case MessageType::UpdateTranslationUnitsForEditorMessage: qDebug() << messageEnvelop.message<UpdateTranslationUnitsForEditorMessage>(); break; case MessageType::UnregisterTranslationUnitsForEditorMessage: qDebug() << messageEnvelop.message<UnregisterTranslationUnitsForEditorMessage>(); break; case MessageType::RegisterProjectPartsForEditorMessage: qDebug() << messageEnvelop.message<RegisterProjectPartsForEditorMessage>(); break; case MessageType::UnregisterProjectPartsForEditorMessage: qDebug() << messageEnvelop.message<UnregisterProjectPartsForEditorMessage>(); break; case MessageType::RegisterUnsavedFilesForEditorMessage: qDebug() << messageEnvelop.message<RegisterUnsavedFilesForEditorMessage>(); break; case MessageType::UnregisterUnsavedFilesForEditorMessage: qDebug() << messageEnvelop.message<UnregisterUnsavedFilesForEditorMessage>(); break; case MessageType::CompleteCodeMessage: qDebug() << messageEnvelop.message<CompleteCodeMessage>(); break; case MessageType::RequestDocumentAnnotationsMessage: qDebug() << messageEnvelop.message<RequestDocumentAnnotationsMessage>(); break; case MessageType::UpdateVisibleTranslationUnitsMessage: qDebug() << messageEnvelop.message<UpdateVisibleTranslationUnitsMessage>(); break; case MessageType::AliveMessage: qDebug() << "AliveMessage()"; break; case MessageType::EchoMessage: qDebug() << messageEnvelop.message<EchoMessage>(); break; case MessageType::CodeCompletedMessage: qDebug() << messageEnvelop.message<CodeCompletedMessage>(); break; case MessageType::TranslationUnitDoesNotExistMessage: qDebug() << messageEnvelop.message<TranslationUnitDoesNotExistMessage>(); break; case MessageType::ProjectPartsDoNotExistMessage: qDebug() << messageEnvelop.message<ProjectPartsDoNotExistMessage>(); break; case MessageType::DocumentAnnotationsChangedMessage: qDebug() << messageEnvelop.message<DocumentAnnotationsChangedMessage>(); break; default: qWarning() << "Unknown Message"; } debug.nospace() << ")"; return debug; }
void ServerThread::initialize() { isInitialized = true; MessageEnvelop e; QDataStream str(s); try { str >> e; } catch(MessageException e) { return; } qDebug() << e.getRequestType() << " initialize on data " << e.getName(); if(e.getRequestType() == REGISTER_TO_SERVER) { registerNewClient(e); return; } if(e.getRequestType() != SEND_LOGIN_TO_SERVER) { sendError("The Connection is bad Mkay. You should try it again M'Kay"); emit error(s->error()); //s->deleteLater(); //emit disconnected(); return; } bool result = false; try { result = verify(e.getName(), e.getPassword()); } catch (SqlConnection::SqlException e) { sendError("The username is not in the database M'kay"); emit error(s->error()); return; } if(!result) { sendError("The password is bad M'kay"); emit error(s->error()); return; } ConnectedClient * c = new ConnectedClient(s->peerAddress(), e.getName(), s->peerPort(), this); qDebug() << "The host " << e.getName() << " on address " << s->peerAddress() << " on port " << s->peerPort(); c->init(this); qDebug() << "opened connection to " << e.getName(); if(!list->addClient(c)) { sendError("The connection already exists M'kay"); emit error(s->error()); } this->c = c; this->name = e.getName(); list->callAllClients(); }