void VeloHeroUploader::dispatchReply( QNetworkReply *reply ) { if( reply->error() != QNetworkReply::NoError ){ parent->errorLabel->setText( tr("request failed: ") + reply->errorString() ); eventLoop.exec(); return; } QVariant status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ); if( ! status.isValid() || status.toInt() != 200 ){ QVariant msg( reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ) ); parent->errorLabel->setText( tr("request failed, server response: %1 %2") .arg(status.toInt()) .arg(msg.toString()) ); eventLoop.quit(); return; } switch( currentRequest ){ case reqSession: finishSession( reply ); break; case reqUpload: finishUpload( reply ); break; } }
void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) { if (isInitialized()) { onElementReceived(element); } else { if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) { if (authRequest->getMechanism() == "PLAIN" || (allowSASLEXTERNAL && authRequest->getMechanism() == "EXTERNAL")) { if (authRequest->getMechanism() == "EXTERNAL") { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); authenticated_ = true; getXMPPLayer()->resetParser(); } else { PLAINMessage plainMessage(authRequest->getMessage() ? *authRequest->getMessage() : createSafeByteArray("")); if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), getLocalJID().getDomain()), plainMessage.getPassword())) { getXMPPLayer()->writeElement(boost::make_shared<AuthSuccess>()); user_ = plainMessage.getAuthenticationID(); authenticated_ = true; getXMPPLayer()->resetParser(); } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(AuthenticationFailedError); } } } else { getXMPPLayer()->writeElement(boost::shared_ptr<AuthFailure>(new AuthFailure)); finishSession(NoSupportedAuthMechanismsError); } } else if (IQ* iq = dynamic_cast<IQ*>(element.get())) { if (boost::shared_ptr<ResourceBind> resourceBind = iq->getPayload<ResourceBind>()) { setRemoteJID(JID(user_, getLocalJID().getDomain(), resourceBind->getResource())); boost::shared_ptr<ResourceBind> resultResourceBind(new ResourceBind()); resultResourceBind->setJID(getRemoteJID()); getXMPPLayer()->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind)); } else if (iq->getPayload<StartSession>()) { getXMPPLayer()->writeElement(IQ::createResult(getRemoteJID(), iq->getID())); setInitialized(); } } } }
void clientHandler(int clientSocket) { // connection error if(clientSocket < 0){ printf("%s", "Error connecting to clientSocket.\n"); exit(EXIT_FAILURE); } int in_session = -1; // read from client char buffer[256]; // buffer for socket messages while(1){ bzero((void*) buffer, 256); if((read(clientSocket, buffer, 255)) <= 0){ // no response exit(EXIT_SUCCESS); } // parse command char *command = strtok(buffer, " \n"); char *commandArg = strtok(NULL, " \n"); if(strcmp(command, "open") == 0){ // open account openAccount(clientSocket, commandArg, &in_session); } else if(strcmp(command, "start") == 0){ // start account session startAccount(clientSocket, commandArg, &in_session); } else if(strcmp(command, "credit") == 0){ // credit account creditAccount(clientSocket, commandArg, &in_session); } else if(strcmp(command, "debit") == 0){ // debit account debitAccount(clientSocket, commandArg, &in_session); } else if(strcmp(command, "balance") == 0){ // get balance getBalance(clientSocket, &in_session); } else if(strcmp(command, "finish") == 0){ // finish finishSession(clientSocket, &in_session); } else{ printf("%s", "Client done goofed, abort mission."); exit(EXIT_FAILURE); } } return; }
void TtbDialog::dispatchReply( QNetworkReply *reply ) { if( reply->error() != QNetworkReply::NoError ){ progressLabel->setText( tr("request failed: ") + reply->errorString() ); closeButton->setText(tr("&Close")); return; } QVariant status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ); if( ! status.isValid() || status.toInt() != 200 ){ QVariant msg( reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ) ); progressLabel->setText( tr("request failed, Server response: %1 %2") .arg(status.toInt()) .arg(msg.toString()) ); closeButton->setText(tr("&Close")); return; } switch( currentRequest ){ case reqSettings: finishSettings( reply ); break; case reqSession: finishSession( reply ); break; case reqUpload: finishUpload( reply ); break; } }