ior-handler.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 615 行 · 第 1/2 页

CPP
615
字号
                  ulongValue));
     ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;

  // Read the 4 octets, which should equal 0 (TAG_INTERNET_IOP = 0)
  ulongValue = getOctet8Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue != 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "TAG_INTERNET_IOP != 0\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;

  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
  numHexCharsRead += numCharsToSkip;

  // Read the 4 octets, which represent the length of the ProfileBody
  ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "ProfileBody len equals 0\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  thisIorInfo->profileBodyLen = ulongValue;

  ACE_DEBUG ((LM_DEBUG,
              "\nTAG_INTERNET_IOP Profile (%d bytes):\n",
              ulongValue));

  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 1);
  numHexCharsRead += numCharsToSkip;

  // Read the 4 octets, which represent the IIOP version number = 1
  // Read the major number of the IIOP Version (should be 1)
  ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue != 1)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "IIOP major version != 1\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  ACE_DEBUG ((LM_DEBUG,
              "IIOP Version: %d.",
              ulongValue));

  // Read the minor number of the IIOP Version (can be 0 or 1)
  ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if ((ulongValue != 0) && (ulongValue != 1) && (ulongValue != 2))
    {
      ACE_DEBUG ((LM_DEBUG,
                  "IIOP minor version != 0, 1, or 2\n"));
     ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  ACE_DEBUG ((LM_DEBUG,
              "%d\n",
              ulongValue));

  skipSpaceIfAny((char *)(thisIor + numHexCharsRead), &numCharsToSkip);
  numHexCharsRead += numCharsToSkip;
  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
  numHexCharsRead += numCharsToSkip;

  // Read the 2 octets, which represent the length of the hostname
  ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "hostLen equals 0\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  thisIorInfo->hostLen = ulongValue;
  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 1);
  numHexCharsRead += numCharsToSkip;

  // Read the hostname and store it
  ACE_OS::strncpy (thisIorInfo->HostName,
                   getString((char *)(thisIor + numHexCharsRead),
                             2 * thisIorInfo->hostLen), thisIorInfo->hostLen);
  numHexCharsRead += 2 * thisIorInfo->hostLen;

  ACE_DEBUG ((LM_DEBUG,
              "    HostName   : %s (%d bytes)\n",
              thisIorInfo->HostName,
              thisIorInfo->hostLen));

  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
  numHexCharsRead += numCharsToSkip;

  // Read the port number and store it
  ulongValue = getOctet4Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "port number equals 0\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  thisIorInfo->portNum = ulongValue;

  ACE_DEBUG ((LM_DEBUG,
              "    Port Number: %d\n",
              thisIorInfo->portNum));

  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
  numHexCharsRead += numCharsToSkip;

  // Read the object key length
  ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                              &numCharsToSkip);

  if (ulongValue == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "objectKeyLen equals 0\n"));
      ACE_OS::exit (1);
    }

  numHexCharsRead += numCharsToSkip;
  thisIorInfo->objectKeyLen = ulongValue;

  skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 1);
  numHexCharsRead += numCharsToSkip;

  // VisiBroker tends to insert the preamble "PMC" (=> Post Modern
  // Computing), before the "real" object key actually starts. Identify
  // if this is the case.
  isVisiIor = findIfVisiIor((char *)(thisIor + numHexCharsRead),
                            &numCharsToSkip);
  if (isVisiIor)
    {
      numHexCharsRead += numCharsToSkip;
      skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
      numHexCharsRead += numCharsToSkip;

      ACE_DEBUG ((LM_DEBUG,
                  "    ObjectKey  : PMC"));

      skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 0);
      numHexCharsRead += numCharsToSkip;

      // Read the real object key length and then the real object key
      ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                                  &numCharsToSkip);

      if (ulongValue == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "VisiBroker IOR - real objectKeyLen equals 0\n"));
          ACE_OS::exit (1);
        }

      numHexCharsRead += numCharsToSkip;

      ACE_OS::strncpy (thisIorInfo->objectKey,
                       getString((char *)(thisIor + numHexCharsRead),
                                 2 * ulongValue), ulongValue);

      numHexCharsRead += 2 * ulongValue;

      ACE_DEBUG ((LM_DEBUG,
                  "%s",
                  thisIorInfo->objectKey,
                  ulongValue));

      skipNullOctets((char *)(thisIor + numHexCharsRead), &numCharsToSkip, 1);
      numHexCharsRead += numCharsToSkip;

      // Read the object name length and then the object name
      ulongValue = getOctet2Field((char *)(thisIor + numHexCharsRead),
                                  &numCharsToSkip);

      if (ulongValue == 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "\n[No object name] (%d bytes)\n\n",
                      thisIorInfo->objectKeyLen));
          ACE_OS::exit (1);
        }

      numHexCharsRead += numCharsToSkip;

      ACE_OS::strncpy (thisIorInfo->objectKey,
                       getString((char *)(thisIor + numHexCharsRead),
                                 2 * ulongValue), ulongValue);

      numHexCharsRead += 2 * ulongValue;

      ACE_DEBUG ((LM_DEBUG,
                  "[object name: %s] (%d bytes)\n\n",
                  thisIorInfo->objectKey,
                  thisIorInfo->objectKeyLen));
    }

  else
    {
      // Non-VisiBroker IOR - Read the object_key and store it
      ACE_OS::strncpy (thisIorInfo->objectKey,
                       getString((char *)(thisIor + numHexCharsRead),
                                 2 * thisIorInfo->objectKeyLen),
                       thisIorInfo->objectKeyLen);

      numHexCharsRead += 2 * thisIorInfo->objectKeyLen;

      ACE_DEBUG ((LM_DEBUG,
                  "    ObjectKey  : %s (%d bytes)\n\n",
                  thisIorInfo->objectKey,
                  thisIorInfo->objectKeyLen));
    }

}


char *
IorHandler::getIdlInterface (char *typeId, int *validTypeId)
{
  static char idlInterface[MAX_TYPE_ID_LEN];
  int lenInterface;

  // A sample type_id for an IDL interface name "EchoTests" is
  // IDL:EchoTests:1.0 => the trick is to isolate the parts between
  // the two colons.
  if ((*typeId != 'I') && (*(typeId+1) != 'D') && (*(typeId+2) != 'L'))
    {
      *validTypeId = 0;
      return ((char *)typeId);
    }

  char *readStart = ACE_OS::strchr(typeId, ':');

  if (readStart == NULL)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "getIdlInterface: type_id contains no starting :\n"));
      ACE_OS::exit (1);
    }


  char *readEnd = ACE_OS::strrchr (typeId, ':');

  if (readEnd == NULL)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "getIdlInterface: type_id contains no ending:\n"));
      ACE_OS::exit (1);
    }

  // Now, count the number of bytes between the two colons.
  lenInterface = readEnd - readStart - 1;

  // Copy the IDL interface part of the type_id.
  ACE_OS::strncpy ((char *)idlInterface,
                   readStart+1,
                   lenInterface);
  idlInterface[lenInterface] = '\0';

  *validTypeId = 1;
  return (char *) idlInterface;
}

void
IorHandler::readIorFromFile (char *filename)
{
  FILE *fp = ACE_OS::fopen (filename, "r");

  // Read the real IOR from the file REAL_IOR_FILE.
  if (fp == NULL)
    {
      ACE_ERROR ((LM_ERROR,
                  "%p\n",
                  "Unable to open file"));
      ACE_OS::exit (1);
    }

  fscanf (fp,
          "%s",
          stringIOR);
  ACE_OS::fclose (fp);

  interpretIor (stringIOR, &parsedIOR);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?