Example #1
0
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 ;
}
Example #2
0
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();
}
Example #3
0
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;
}
Example #5
0
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;
}
Example #6
0
	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;
	}
Example #7
0
void DataFetcher::makeHead(const QUrl &url)
{
    log( tr("Make HEAD request: %1").arg( url.toString() ) );

    reset();
    reply = nam->head( QNetworkRequest(url) );
    handleReply();
}
Example #8
0
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;
}
Example #9
0
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;
}
Example #10
0
// 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)) {
	}
}
Example #11
0
// 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)) {
	}
}
Example #12
0
void Client::onDeactivate() {
	Json::Value req;
	req["method"] = "onDeactivate";

	Json::Value ret;
	sendRequest(req, ret);
	if (handleReply(ret)) {
	}
	LangBarButton::clearIconCache();
	isActivated_ = false;
}
Example #13
0
// 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;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
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;
}
Example #17
0
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();
}
Example #18
0
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;
}
Example #19
0
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;
}
Example #20
0
/** <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!"));
}
Example #21
0
// 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)) {
		}
	}
}
Example #22
0
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)) {
	}
}
Example #23
0
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;
}
Example #24
0
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);
}
Example #25
0
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);
}
Example #26
0
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 ;
}
Example #27
0
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);
}
Example #28
0
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);  
}
Example #29
0
void IRC::finishPrivmsg(void* deferred, void* waiton) {

	// deferred == NULL
	handleReply(static_cast<ClientQueryData*>(waiton));

}
Example #30
0
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;
}