Ejemplo n.º 1
0
static PGPError
BufferSizeAdvise(PGPPipeline *myself, unsigned long size)
{
	AddHdrContext *context;
	PGPError	error;
	int i;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);
	pgpAssert(context->buffer);

	/* Do not pass non-zero sizeAdvise -- I can't do that! */
	if (size || context->scope_depth)
		return( kPGPError_NoErr );

	/* Okay, we're at end of input. */
	if (context->buflen) {
		/* We have a bug when file length is zero; we get here without having
		 * flushed the header.  We can't easily distinguish between a zero
		 * length file and the EOF sizeadvise, but we don't need to.
		 */
		error = FlushHeader(context);
		if (error)
			return error;
		if (context->dowrite) {
			error = FlushBuffer(context);
		} else if (context->midflush) {
			error = ForceFlush(context);
		} else {
			i = context->buflen;
			if (PKTLEN_ONE_BYTE(i)) {
				context->bufptr--;
				context->buflen++;
				context->bufptr[0] = PKTLEN_1BYTE(i);
			} else {
				context->bufptr -= 2;
				context->buflen += 2;
				context->bufptr[0] = PKTLEN_BYTE0(i);
				context->bufptr[1] = PKTLEN_BYTE1(i);
			}
			context->midflush = context->buflen;
			error = ForceFlush(context);
		}
		if (error)
			return error;
	}
	
	return context->tail->sizeAdvise(context->tail, 0);
}
Ejemplo n.º 2
0
static PGPError
Flush(PGPPipeline *myself)
{
	AddHdrContext *context;
	PGPError	error;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);

	if (context->buffer) {
		error = FlushHeader(context);
		if (error)
			return error;

		/* Using the new packets -- force a flush of the buffer */
		if (context->dowrite) {
			error = FlushBuffer(context);
			if (error)
				return error;
		} else {
			error = ForceFlush(context);
			if (error)
				return error;
		}

	} else {
		/* Using the fifo */

		if (!context->dowrite)
			return kPGPError_BadParams;

		error = DoFlush(context);
		if (error)
			return error;
	}

	return context->tail->flush(context->tail);
}
Ejemplo n.º 3
0
// Hexadecimal view of an object added to the logfile
bool    
LogAnalysis::AnalysisHex(const char* p_function,CString p_name,void* p_buffer,unsigned long p_length,unsigned p_linelength /*=16*/)
{
  // Only dump in the logfile, not to the MS-Windows event log
  if(!m_file || m_logLevel < HLL_TRACEDUMP)
  {
    return false;
  }

  // Check parameters
  if(p_linelength > LOGWRITE_MAXHEXCHARS)
  {
    p_linelength = LOGWRITE_MAXHEXCHARS;
  }
  if(p_length > LOGWRITE_MAXHEXDUMP)
  {
    p_length = LOGWRITE_MAXHEXDUMP;
  }

  // Multi threaded protection
  AutoCritSec lock(&m_lock);

  // Name of the object
  AnalysisLog(p_function,LogType::LOG_TRACE,true,"Hexadecimal view of: %s. Length: %d",p_name.GetString(),p_length);

  unsigned long  pos    = 0;
  unsigned char* buffer = static_cast<unsigned char*>(p_buffer);

  while(pos < p_length)
  {
    unsigned len = 0;
    CString hexadLine;
    CString asciiLine;

    // Format one hexadecimal view line
    while(pos < p_length && len < p_linelength)
    {
      // One byte at the time
      hexadLine.AppendFormat("%2.2X ",*buffer);
      if(*buffer)
      {
        asciiLine += *buffer;
      }
      // Next byte in the buffer
      ++buffer;
      ++pos;
      ++len;
    }

    // In case of an incomplete last line
    while(len++ < p_linelength)
    {
      hexadLine += "   ";
    }
    asciiLine.Replace("\r","#");
    asciiLine.Replace("\n","#");

    // Add to the list buffer
    CString line(hexadLine + asciiLine + "\n");
    m_list.push_back(line);
  }
  // Large object now written to the buffer. Force write it
  ForceFlush();

  return true;
}