int InsertCommand::execute( ossSocket & sock, std::vector<std::string> & argVec ) { int rc = EDB_OK; if( argVec.size() <1 ) { return getError(EDB_INSERT_INVALID_ARGUMENT); } _jsonString = argVec[0]; if( !sock.isConnected() ) { return getError(EDB_SOCK_NOT_CONNECT); } rc = sendOrder( sock, msgBuildInsert ); PD_RC_CHECK ( rc, PDERROR, "Failed to send order, rc = %d", rc ) ; rc = recvReply( sock ); PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc ) ; rc = handleReply(); PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc ) ; done : return rc; error : goto done ; }
void QGeoTileFetcher::requestNextTile() { Q_D(QGeoTileFetcher); QMutexLocker ml(&d->queueMutex_); if (d->stopped_) return; if (d->queue_.isEmpty()) { d->timer_->stop(); return; } QGeoTileSpec ts = d->queue_.takeFirst(); QGeoTiledMapReply *reply = getTileImage(ts); if (reply->isFinished()) { handleReply(reply, ts); } else { connect(reply, SIGNAL(finished()), this, SLOT(finished()), Qt::QueuedConnection); d->invmap_.insert(ts, reply); } if (d->queue_.isEmpty()) d->timer_->stop(); }
void KWebPage::downloadResponse(QNetworkReply *reply) { Q_ASSERT(reply); if (!reply) return; // Put the job on hold only for the protocols we know about (read: http). KIO::Integration::AccessManager::putReplyOnHold(reply); QString mimeType; KIO::MetaData metaData; if (handleReply(reply, &mimeType, &metaData)) { return; } const KUrl replyUrl (reply->url()); // Ask KRun to handle the response when mimetype is unknown if (mimeType.isEmpty()) { (void)new KRun(replyUrl, d->windowWidget(), 0 , replyUrl.isLocalFile()); return; } // Ask KRun::runUrl to handle the response when mimetype is inode/* if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive) && KRun::runUrl(replyUrl, mimeType, d->windowWidget(), false, false, metaData.value(QL1S("content-disposition-filename")))) { return; } }
bool AbstractQueryItem::load() { if (m_account == nullptr || !isQueryValid() || m_status == Loading) { return false; } QNetworkReply *reply = createQuery(); setStatusAndErrorMessage(Loading, QString()); connect(reply, &QNetworkReply::finished, this, [this, reply]() { QObjectPtr<QNetworkReply> replyPtr {reply}; const QByteArray &data {replyPtr->readAll()}; handleReply(data, replyPtr->error(), replyPtr->errorString()); if (m_status == Loading) { if (replyPtr->error() != QNetworkReply::NoError) { qCWarning(QLoggingCategory("query-item")) << "Error happened during query"; qCWarning(QLoggingCategory("query-item")) << "Error code:" << replyPtr->error(); qCWarning(QLoggingCategory("query-item")) << "Error message (Qt):" << replyPtr->errorString(); qCWarning(QLoggingCategory("query-item")) << "Error message (Twitter):" << data; setStatusAndErrorMessage(Error, tr("Network error. Please try again later.")); } else { setStatusAndErrorMessage(Idle, QString()); } } }); return true; }
void STULogin::login(const QString &user, const QString &passwd){ // qDebug() << "now login " + user + "\t" + passwd; logining = true; // QtNetWorkAccessManager works asynchronously this->user_copy = user; // qDebug() << this->user; this->passwd = passwd; // record the user info for try again untill MAX_COUNT or login if (is_connected){ wrongCount = 0; return; } requestAddr->setUrl(LOGIN_REQUEST_ADDR); QUrl params; params.addQueryItem(USERNAME_INPUT,user); params.addQueryItem(PASSWD_INPUT,passwd); params.addQueryItem(LOGIN_INPUT,""); QByteArray postData = params.encodedQuery(); QNetworkRequest request(*requestAddr); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); delayForSomeTime(600); QNetworkReply *reply = syncHttpPost(request, postData); handleReply(reply); processStates(replyData); emit stateChanged(is_connected,user,used,total,left); //qDebug() << replyData; }
void Plugin::hookURLCompletionNewStringRequested (IHookProxy_ptr, QObject *model, const QString& string, int) { if (Model2Reply_.contains (model)) { auto reply = Model2Reply_.take (model); Reply2Model_.remove (reply); delete reply; } if (string.isEmpty ()) return; QUrl reqUrl ("http://clients1.google.com/complete/search"); Util::UrlOperator { reqUrl } ("hl", "en") ("output", "toolbar") ("q", string); auto reply = Proxy_->GetNetworkAccessManager ()->get (QNetworkRequest (reqUrl)); connect (reply, SIGNAL (finished ()), this, SLOT (handleReply ())); Model2Reply_ [model] = reply; Reply2Model_ [reply] = model; }
void DataFetcher::makeHead(const QUrl &url) { log( tr("Make HEAD request: %1").arg( url.toString() ) ); reset(); reply = nam->head( QNetworkRequest(url) ); handleReply(); }
void CmdEval::onClient(DebuggerClient &client) { m_body = client.getCode(); m_frame = client.getFrame(); m_bypassAccessCheck = client.getDebuggerClientBypassCheck(); auto res = client.xendWithNestedExecution<CmdEval>(this); res->handleReply(client); m_failed = res->m_failed; }
void CmdEval::onClient(DebuggerClient &client) { m_body = client.getCode(); m_frame = client.getFrame(); m_bypassAccessCheck = client.getDebuggerClientBypassCheck(); auto res = client.xendWithNestedExecution<CmdEval>(this); assertx(res->is(DebuggerCommand::KindOfEval)); auto eval = std::static_pointer_cast<CmdEval>(res); eval->handleReply(client); m_failed = eval->m_failed; }
// called just before current composition is terminated for doing cleanup. void Client::onCompositionTerminated(bool forced) { Json::Value req; req["method"] = "onCompositionTerminated"; req["forced"] = forced; Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } }
// called when the keyboard is opened or closed void Client::onKeyboardStatusChanged(bool opened) { Json::Value req; req["method"] = "onKeyboardStatusChanged"; req["opened"] = opened; Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } }
void Client::onDeactivate() { Json::Value req; req["method"] = "onDeactivate"; Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } LangBarButton::clearIconCache(); isActivated_ = false; }
// handlers for the text service void Client::onActivate() { Json::Value req; req["method"] = "onActivate"; req["isKeyboardOpen"] = textService_->isKeyboardOpened(); Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } isActivated_ = true; }
bool Client::sendOnMenu(std::string button_id, Json::Value& result) { Json::Value req; req["method"] = "onMenu"; req["id"] = button_id; sendRequest(req, result); if (handleReply(result)) { return true; } return false; }
bool Client::onKeyUp(Ime::KeyEvent& keyEvent, Ime::EditSession* session) { Json::Value req; req["method"] = "onKeyUp"; keyEventToJson(keyEvent, req); Json::Value ret; sendRequest(req, ret); if (handleReply(ret, session)) { return ret["return"].asBool(); } return false; }
bool Client::filterKeyUp(Ime::KeyEvent& keyEvent) { Json::Value req; req["method"] = "filterKeyUp"; keyEventToJson(keyEvent, req); Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { return ret["return"].asBool(); } return false; }
void DataFetcher::makePost(const QUrl &url, const QByteArray &postData) { log( tr("Make POST request: %1").arg( url.toString() ) ); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); request.setHeader( QNetworkRequest::ContentLengthHeader, postData.size() ); reset(); reply = nam->post(request, postData); handleReply(); }
int QuitCommand::execute( ossSocket & sock, std::vector<std::string> & argVec ) { int ret = EDB_OK; if( !sock.isConnected() ) { return getError(EDB_SOCK_NOT_CONNECT); } ret = sendOrder( sock, 0 ); //sock.close(); ret = handleReply(); return ret; }
bool Client::onCommand(UINT id, Ime::TextService::CommandType type) { Json::Value req; req["method"] = "onCommand"; req["id"] = id; req["type"] = type; Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { return ret["return"].asBool(); } return false; }
/** <b>popis metody</b>\n metoda na zpracovani spojeni pd druheho klienta @return void */ void Server::handleNewConnection() { // ziskamesocket this->socket = this->server->nextPendingConnection(); if(!this->socket) return; connect(this->socket, SIGNAL(readyRead()), SLOT(handleReply())); //spojeni this->game->setNetworkRole(SERVER); this->game->newGame(NETWORK); this->game->printInfo(INFO, QString("Connection successful"),QString("Someone connected to you!")); }
// called when a compartment value is changed void Client::onCompartmentChanged(const GUID& key) { LPOLESTR str = NULL; if (SUCCEEDED(::StringFromCLSID(key, &str))) { Json::Value req; req["method"] = "onCompartmentChanged"; req["guid"] = utf16ToUtf8(str); ::CoTaskMemFree(str); Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } } }
void Client::init() { Json::Value req; req["method"] = "init"; req["id"] = guid_.c_str(); // language profile guid req["isWindows8Above"] = textService_->imeModule()->isWindows8Above(); req["isMetroApp"] = textService_->isMetroApp(); req["isUiLess"] = textService_->isUiLess(); req["isConsole"] = textService_->isConsole(); Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { } }
bool Client::onPreservedKey(const GUID& guid) { LPOLESTR str = NULL; if (SUCCEEDED(::StringFromCLSID(guid, &str))) { Json::Value req; req["method"] = "onPreservedKey"; req["guid"] = utf16ToUtf8(str); ::CoTaskMemFree(str); Json::Value ret; sendRequest(req, ret); if (handleReply(ret)) { return ret["return"].asBool(); } } return false; }
void STULogin::logout(){ logining = false; // need this flag becuase the school server sucks wrongCount = 0; requestAddr->setUrl(LOGOUT_REQUEST_ADDR); QUrl params; params.addQueryItem(LOGOUT_INPUT,""); QByteArray postData = params.encodedQuery(); QNetworkRequest request(*requestAddr); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QNetworkReply *reply = syncHttpPost(request, postData); handleReply(reply); processStates(replyData); if (is_connected && autoChange && left <= thresholdValue) logout(); // until logout emit stateChanged(is_connected,user,used,total,left); }
bool AuthService::event(QEvent *event) { if(event->type() == Request::eventType()) { debug() << "New request"; Request *request = static_cast<Request*>(event); AuthDialogPrivate *dialog = new AuthDialogPrivate(); connect(dialog,SIGNAL(accepted()), SLOT(onAccepted())); connect(dialog,SIGNAL(rejected()), SLOT(onRejected())); dialog->show(request->contact(), request->body(), false); return true; } else if(event->type() == Reply::eventType()) { handleReply(static_cast<Reply*>(event)); return true; } return QObject::event(event); }
int SnapshotCommand::execute( ossSocket & sock, std::vector<std::string> &argVec) { int rc = EDB_OK; if( !sock.isConnected() ) { return getError(EDB_SOCK_NOT_CONNECT); } rc = sendOrder( sock, OP_SNAPSHOT ); PD_RC_CHECK ( rc, PDERROR, "Failed to send order, rc = %d", rc); rc = recvReply( sock ); PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc); rc = handleReply(); PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc); done : return rc; error : goto done ; }
void QGeoTileFetcher::finished() { Q_D(QGeoTileFetcher); QMutexLocker ml(&d->queueMutex_); QGeoTiledMapReply *reply = qobject_cast<QGeoTiledMapReply *>(sender()); if (!reply) return; QGeoTileSpec spec = reply->tileSpec(); if (!d->invmap_.contains(spec)) { reply->deleteLater(); return; } d->invmap_.remove(spec); handleReply(reply, spec); }
void ServerConnection::receive() { int res = tcp_recv_msg(conn.dia_conn, &conn.rb, 0, CONN_WAIT_USECS); if (res < 0) { if (res == AAA_CONN_SHUTDOWN) { INFO( M_NAME "receive(): shutdown - closing connection.\n"); closeConnection(true); } else { closeConnection(); ERROR( M_NAME "receive(): tcp_recv_reply() failed.\n"); } return; } if (!res) // nothing received return; /* obtain the structure corresponding to the message */ AAAMessage* msg = AAATranslateMessage(conn.rb.buf, conn.rb.buf_len, 0); if(!msg) { ERROR( M_NAME "receive(): message structure not obtained from message.\n"); closeConnection(); return; } #ifdef EXTRA_DEBUG AAAPrintMessage(msg); #endif if (is_req(msg)) handleRequest(msg); else handleReply(msg); AAAFreeMessage(&msg); }
void IRC::finishPrivmsg(void* deferred, void* waiton) { // deferred == NULL handleReply(static_cast<ClientQueryData*>(waiton)); }
int main(int argc, char** argv) { OptionParser options; options.executable(argv[0]) .program(DUNE_SHORT_NAME) .copyright(DUNE_COPYRIGHT) .email("Renato Caldas <*****@*****.**>") .version(getFullVersion()) .date(getCompileDate()) .arch(DUNE_SYSTEM_NAME) .description("Utility to update firmware of LUCL based devices.") .add("-d", "--sys-device", "System device", "DEVICE") .add("-i", "--i2c-address", "I2C slave address", "I2C_ADDR") .add("-c", "--command", "LUCL command", "CMD") .add("-p", "--data-payload", "LUCL data", "DATA0[,DATA1 ...]"); // Parse command line arguments. if (!options.parse(argc, argv)) { if (options.bad()) std::cerr << "ERROR: " << options.error() << std::endl; options.usage(); return 1; } // Get system device. std::string sys_dev = options.value("--sys-device"); if (sys_dev.empty()) { std::cerr << "ERROR: you must specify one system device." << std::endl; return 1; } // Get I2C address (if any). bool is_i2c = false; uint8_t i2c_addr = 0; if (castLexical(options.value("--i2c-address"), i2c_addr)) { if ((i2c_addr < 0x03) || (i2c_addr > 0x77)) { std::cerr << "ERROR: I2C device address is out of range (0x03 - 0x77)" << std::endl; return 1; } is_i2c = true; } // Open the device LUCL::Protocol proto; if (is_i2c) proto.setI2C(sys_dev, i2c_addr); else proto.setUART(sys_dev); try { proto.open(); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } // Check for the command token std::string command = options.value("--command"); if (command.empty()) { std::cerr << "ERROR: reading from stdio not supported yet." << std::endl; return 1; } // Get the data payload std::string data_str = options.value("--data-payload"); std::vector<uint8_t> data_lst; if (!castLexical(data_str, data_lst)) { std::cerr << "ERROR: failed to parse the data payload argument." << std::endl; return 1; } // Build and send the packet if (command.compare("Info") == 0) { std::cerr << "Requesting device information" << std::endl; try { proto.requestVersion(); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } else if (command.compare("Reset") == 0) { std::cerr << "Requesting reset" << std::endl; try { proto.requestReset(); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } else { // Command string not recognized, attempt to interpret it as an integer int cmd; if (!castLexical(command, cmd)) { std::cerr << "ERROR: bad command \"" << command << "\"" << std::endl; return 1; } // Print the command and the data in a parseable format std::cout << "Sending packet CMD " << cmd << " DATA"; for (unsigned i = 0; i < data_lst.size(); i++) { std::cout << " 0x" << std::hex << (int)data_lst[i]; } std::cout << std::endl; try { proto.sendCommand(cmd, (uint8_t*)(&data_lst[0]), (int)data_lst.size()); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } // Handle the results handleReply(proto); return 0; }