Esempio n. 1
0
GpgME::Error Kleo::QGpgMEKeyListJob::start( const QStringList & pats, bool secretOnly ) {
  setup( pats, secretOnly );

  hookupContextToEventLoopInteractor();
  connect( QGpgME::EventLoopInteractor::instance(),
	   SIGNAL(nextKeyEventSignal(GpgME::Context*,const GpgME::Key&)),
	   SLOT(slotNextKeyEvent(GpgME::Context*,const GpgME::Key&)) );

  // The communication channel between gpgme and gpgsm is limited in
  // the number of patterns that can be transported, but they won't
  // say to how much, so we need to find out ourselves if we get a
  // LINE_TOO_LONG error back...

  // We could of course just feed them single patterns, and that would
  // probably be easier, but the performance penalty would currently
  // be noticable.

  while ( const GpgME::Error err = mCtx->startKeyListing( patterns(), mSecretOnly ) ) {
    if ( err.code() == GPG_ERR_LINE_TOO_LONG ) {
      setChunkSize( chunkSize()/2 );
      if ( chunkSize() >= 1 ) {
	kdDebug(5150) << "QGpgMEKeyListJob::start(): retrying keylisting with chunksize " << chunkSize() << endl;
	continue;
      }
    }
    deleteLater();
    mResult = GpgME::KeyListResult( 0, err );
    return err;
  }
  mResult = GpgME::KeyListResult( 0, 0 );
  return 0;
}
Esempio n. 2
0
GpgME::KeyListResult Kleo::QGpgMEKeyListJob::exec( const QStringList & pats, bool secretOnly, std::vector<GpgME::Key> & keys ) {
  setup( pats, secretOnly );

  // The communication channel between gpgme and gpgsm is limited in
  // the number of patterns that can be transported, but they won't
  // say to how much, so we need to find out ourselves if we get a
  // LINE_TOO_LONG error back...

  // We could of course just feed them single patterns, and that would
  // probably be easier, but the performance penalty would currently
  // be noticable.

  for (;;) {
    keys.clear();
    mResult = attemptSyncKeyListing( keys );
    if ( !mResult.error() || mResult.error().code() != GPG_ERR_LINE_TOO_LONG )
      return mResult;
    // got LINE_TOO_LONG, try a smaller chunksize:
    setChunkSize( chunkSize()/2 );
    if ( chunkSize() < 1 )
      // chunks smaller than one can't be -> return the error.
      return mResult;
    kdDebug(5150) << "QGpgMEKeyListJob::exec(): retrying keylisting with chunksize " << chunkSize() << endl;
  }
  kdFatal(5150) << "QGpgMEKeyListJob::exec(): Oops, this is not supposed to happen!" << endl;
  return GpgME::KeyListResult();
}
status_t SimpleSocketConnection::open()
{
    status_t error = SocketConnection::open();
    if (!error)
    {
        uint_t size = chunkSize_;
#ifdef NDEBUG
        status_t ignore = socket().getMaxTcpSegmentSize(size);
#else
        status_t ignore = errNone;
# ifdef _PALM_OS
        if (!(underSimulator() && isTreo600())) // These fatal alerts on Treo600 sim really piss me off.
            ignore = socket().getMaxTcpSegmentSize(size);
# endif
#endif                
        if (errNone == ignore)
        {
            if (size <= 2048)
            {
                // LogStrUlong(eLogInfo, _T("SimpleSocketConnection::open(): setting chunkSize to "), size);
                setChunkSize(size);
            }
        }
        else
            LogStrUlong(eLogInfo, _T("SimpleSocketConnection::open(): error (ignored) while querying maxTcpSegmentSize: "), ignore);
    }
    return error;
}
Esempio n. 4
0
/**
 * The main send function
 * @param  fileName The name of the file
 * @return The number of bytes sent
 */
unsigned long sendFile(const char* fileName)
{
	/* Open the file for reading */
	FILE* fp = fopen(fileName, "r");

	/* The number of bytes saved to shared memory */
	size_t chunkSize;

	/* The number of bytes sent */
	unsigned long numBytesSent = 0;
	
	/* Was the file open? */
	if (!fp)
	{
		perror("fopen");
		exit(-1);
	}
	
	/* Advance the shared memory pointer by sizeof(size_t) for writing data
	 * since the first bytes in shared memory will store chunkSize
	 */
	sharedMemPtr = static_cast<char*>(sharedMemPtr) + sizeof(size_t);

	/* Read the whole file */
	while (!feof(fp))
	{
		/* Read at most SHARED_MEMORY_CHUNK_SIZE from the file and store them in shared memory.
 		 * fread will return how many bytes it has actually read (since the last chunk may be less
 		 * than SHARED_MEMORY_CHUNK_SIZE).
 		 */
		if ((chunkSize = fread(sharedMemPtr, sizeof(char), SHARED_MEMORY_CHUNK_SIZE, fp)) < 0)
		{
			perror("fread");
			exit(-1);
		}
		
		/* Store the chunk size in shared memory and advance the shared memory pointer */
		setChunkSize(chunkSize);

		/* Count the number of bytes sent */
		numBytesSent += chunkSize;

		/* Signal the receiver that the data is ready */
		if (kill(rpid, SIGUSR1) < 0)
		{
			perror("kill");
			exit(-1);
		}

		/* Wait for signal from receiver */
		wait(usr_interrupt);
	}
	
	/* Set the size of the chunk to zero to signal that there is no more data to send */
	chunkSize = 0;

	/* Store the chunk size in shared memory and advance the shared memory pointer */
	setChunkSize(chunkSize);

	/* Signal the receiver that the data is ready */
	if (kill(rpid, SIGUSR1) < 0)
	{
		perror("kill");
		exit(-1);
	}

	/* Close the file */
	fclose(fp);
	
	/* Back up the shared memory pointer */
	sharedMemPtr = static_cast<char*>(sharedMemPtr) - sizeof(size_t);

	return numBytesSent;
}