Beispiel #1
0
int _CRTAPI1
main(
    IN int argc,
    IN char *argv[]
    )
{
    NET_API_STATUS       ApiStatus;
    int                  ArgNumber;
    BOOL                 DoingFiles = TRUE;
    REPL_WIN32_FIND_DATA FindData;
    BOOL                 GotPath = FALSE;
    LONG                 MasterTimeZoneOffsetSecs;  // exporter offset from GMT
    CHECKSUM_REC         Record;
    TCHAR                Source[ PATHLEN+1 ];   // area after L'\0' is scratch
    LPTSTR               UncServerName = NULL;  // server where files are.
    BOOL                 Verbose = FALSE;


    //
    // Process command-line arguments.
    //
    for (ArgNumber = 1; ArgNumber < argc; ArgNumber++) {
        if ((*argv[ArgNumber] == '-') || (*argv[ArgNumber] == '/')) {
            switch (tolower(*(argv[ArgNumber]+1))) // Process switches
            {

            case 'd' :
                DoingFiles = FALSE;
                break;

            case 's' :
                if (UncServerName != NULL) {
                    Usage( argv[0] );
                    return (EXIT_FAILURE);
                }
                UncServerName
                        = NetpAllocTStrFromStr( (LPSTR) argv[++ArgNumber]);
                NetpAssert( UncServerName != NULL );
                break;

            case 'v' :
                ReplGlobalTrace = REPL_DEBUG_ALL;
                Verbose = TRUE;
                break;

            default :
                Usage( argv[0] );
                return (EXIT_FAILURE);

            } // switch

        } else {  // not an argument

            if (GotPath) {
                Usage( argv[0] );
                return (EXIT_FAILURE);
            }
            GotPath = TRUE;
            (VOID) NetpCopyStrToTStr(Source, argv[ArgNumber]);
        }
    }

    if ( !GotPath ) {
        Usage( argv[0] );
        return (EXIT_FAILURE);
    }

    assert( Source[0] != TCHAR_EOS );

    //
    // Checksum is based on master's timezone, so get it.
    //
    ApiStatus = ReplGetTimeCacheValue(
            UncServerName,
            &MasterTimeZoneOffsetSecs ); // offset (+ for West of GMT, etc).
    if (ApiStatus != NO_ERROR) {
        (VOID) printf(
                "ReplGetTimeCacheValue FAILED, status " FORMAT_API_STATUS ".\n",
                ApiStatus );
        goto Cleanup;
    }
    if (Verbose) {
        (VOID) printf(
                "Master time zone offset (seconds) is " FORMAT_LONG ".\n",
                MasterTimeZoneOffsetSecs );
    }
    assert( MasterTimeZoneOffsetSecs != -1 );

    //
    // Checksum the file or directory.
    //
    if (DoingFiles) {

        ShowFileTimes( Source );
        FakeFindData(
                Source,    // file name
                Verbose,
                &FindData );

        Record.checksum = SingleChecksum(
                MasterTimeZoneOffsetSecs, // exporter offset from GMT
                &FindData );
        Record.count = 1;

    } else {
        ScanTree(
                MasterTimeZoneOffsetSecs, // exporter offset from GMT
                Source,                // dir name  (and scratch space!)
                &Record );
    }

    (VOID) printf( "checksum for '" FORMAT_LPTSTR "' is:\n",
            Source );
    DumpChecksum( &Record );
    ApiStatus = NO_ERROR;


Cleanup:

    // BUGBUG: memory leaks, but who cares?
    if (ApiStatus == NO_ERROR) {
        return (EXIT_SUCCESS);
    } else {
        return (EXIT_FAILURE);
    }

} // main
Beispiel #2
0
int ProxyReadBuffer::locateMessage(const unsigned char *start,
                                       const unsigned char *end,
                                           unsigned int &controlLength,
                                               unsigned int &dataLength,
                                                   unsigned int &trailerLength)
{
  unsigned int lengthLength = 0;
  const unsigned char *nextSrc = start;
  unsigned char next;

  dataLength = 0;

  #ifdef TEST
  *logofs << "ProxyReadBuffer: Locating message for FD#"
          << transport_ -> fd() << " with " << end - start
          << " bytes.\n" << logofs_flush;
  #endif

  //
  // Use something like the following if
  // you are looking for errors.
  //

  #ifdef DUMP
  if (control -> ProxyMode == proxy_server && start < end &&
          transport_ -> fd() == 6 || transport_ -> fd() == 11)
  {
    *logofs << "ProxyReadBuffer: Partial checksums are:\n";

    DumpBlockChecksums(start, end - start, 256);

    *logofs << logofs_flush;
  }
  #endif

  do
  {
    if (nextSrc >= end)
    {
      remaining_ = 1;

      #ifdef TEST
      *logofs << "ProxyReadBuffer: No message was located "
              << "with remaining " << remaining_ << ".\n"
              << logofs_flush;
      #endif

      return 0;
    }

    next = *nextSrc++;

    dataLength <<= 7;
    dataLength |= (unsigned int) (next & 0x7f);

    lengthLength++;
  }
  while (next & 0x80);

  unsigned int totalLength;

  if (dataLength == 0)
  {
    trailerLength = 0;
    controlLength = 3;
    totalLength   = controlLength;
  }
  else
  {
    trailerLength = lengthLength;
    controlLength = 0;
    totalLength   = dataLength + trailerLength;
  }

  if (start + totalLength > end)
  {
    //
    // When having to decompress a ZLIB stream,
    // a single byte can be enough to complete
    // the frame.
    //

    if (control -> RemoteStreamCompression == 0)
    {
      remaining_ = totalLength - (end - start);
    }
    else
    {
      remaining_ = 1;
    }

    #ifdef TEST
    *logofs << "ProxyReadBuffer: No message was located "
            << "with remaining " << remaining_ << ".\n"
            << logofs_flush;
    #endif

    return 0;
  }
  else
  {
    #ifdef DUMP
    *logofs << "ProxyReadBuffer: Received " << totalLength << " bytes of data "
            << "with checksum ";

    DumpChecksum(start, totalLength);

    *logofs << " on proxy FD#" << transport_ -> fd() << ".\n" << logofs_flush;
    #endif

    #if defined(TEST) || defined(INFO)
    *logofs << "ProxyReadBuffer: Produced plain input for " << dataLength 
            << "+" << trailerLength << "+" << controlLength << " bytes out of " 
            << totalLength << " bytes.\n" << logofs_flush;
    #endif

    #ifdef DUMP
    *logofs << "ProxyReadBuffer: Partial checksums are:\n";

    DumpBlockChecksums(start, totalLength, 256);

    *logofs << logofs_flush;
    #endif

    remaining_ = 0;

    #ifdef TEST
    *logofs << "ProxyReadBuffer: Located message with "
            << "remaining " << remaining_ << ".\n"
            << logofs_flush;
    #endif

    return 1;
  }
}