diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-27 00:36:23 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-27 00:36:23 +0000 |
commit | b523a0e80f50c19de330551d7d33b0c301c891df (patch) | |
tree | 479ad12bfd5b7dfae93b757919027a5c5603f7aa | |
parent | 1678ccdda878fa012646abf6e61a5de085e45e88 (diff) | |
download | ATCD-b523a0e80f50c19de330551d7d33b0c301c891df.tar.gz |
*** empty log message ***
-rw-r--r-- | TAO/utils/IorParser/Makefile | 44 | ||||
-rw-r--r-- | TAO/utils/IorParser/README | 16 | ||||
-rw-r--r-- | TAO/utils/IorParser/TaoSimple.IOR | 1 | ||||
-rw-r--r-- | TAO/utils/IorParser/ior-handler.cpp | 431 | ||||
-rw-r--r-- | TAO/utils/IorParser/ior-handler.h | 99 | ||||
-rw-r--r-- | TAO/utils/IorParser/ior-parser.cpp | 38 | ||||
-rw-r--r-- | TAO/utils/catior/Makefile | 45 |
7 files changed, 674 insertions, 0 deletions
diff --git a/TAO/utils/IorParser/Makefile b/TAO/utils/IorParser/Makefile new file mode 100644 index 00000000000..cc7ff383adc --- /dev/null +++ b/TAO/utils/IorParser/Makefile @@ -0,0 +1,44 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the IOR Parser +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = ior-parser + +FILES = ior-handler + +SRC = $(addsuffix .cpp,$(FILES)) +OBJ = $(addsuffix .o,$(FILES)) + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/TAO/utils/IorParser/README b/TAO/utils/IorParser/README new file mode 100644 index 00000000000..f4fefcb2310 --- /dev/null +++ b/TAO/utils/IorParser/README @@ -0,0 +1,16 @@ +// FILENAME : README +// AUTHOR : Priya Narasimhan +// LAST MODIFIED : June 18, 1998 +// DESCRIPTION : Description of the Ior Parser + +The "parseIor" utility parses IORs generated by most ORBs. It has been +tested with Orbix, VisiBroker and TAO so far. + +USAGE: parseIor <IOR filename> + +There is a sample file in this directory called TaoSimple.IOR that is +an IOR generated using the example $TAO_ROOT/tests/Simple. You can +run the "parseIor" utility against that to see what the output looks +like. + + diff --git a/TAO/utils/IorParser/TaoSimple.IOR b/TAO/utils/IorParser/TaoSimple.IOR new file mode 100644 index 00000000000..830ed119a9c --- /dev/null +++ b/TAO/utils/IorParser/TaoSimple.IOR @@ -0,0 +1 @@ +IOR:000000000000001649444c3a73696d706c655f6f626a6563743a312e3000000000000001000000000000003600010000000000036d750000aada00000000002250333564623666626130303062383766612f6368696c645f706f612f736572766572
\ No newline at end of file diff --git a/TAO/utils/IorParser/ior-handler.cpp b/TAO/utils/IorParser/ior-handler.cpp new file mode 100644 index 00000000000..0ffe4adbb81 --- /dev/null +++ b/TAO/utils/IorParser/ior-handler.cpp @@ -0,0 +1,431 @@ +// $Id$ + +#include "ior-handler.h" + +IorHandler::IorHandler (void) +{ +} + +// @@ Priya, can you please see if you can replace this function with +// the ACE::hex2byte() method? + +int +IorHandler::hexChar2int (char thisChar) +{ + switch (thisChar) + { + case '0': return (0); + case '1': return (1); + case '2': return (2); + case '3': return (3); + case '4': return (4); + case '5': return (5); + case '6': return (6); + case '7': return (7); + case '8': return (8); + case '9': return (9); + case 'a': return (10); + case 'b': return (11); + case 'c': return (12); + case 'd': return (13); + case 'e': return (14); + case 'f': return (15); + } +} + +u_long +IorHandler::getOctet8Field (char *readPtr, int *hexCharsRead) +{ + char octet8Holder[8]; + u_long value; + int i; + + for (i = 0; i < 8; i++) + octet8Holder[i] = * (readPtr + i); + + *hexCharsRead = 8; + + value = 16*hexChar2int (octet8Holder[6]) + hexChar2int (octet8Holder[7]); + return (value); +} + +u_long +IorHandler::getOctet4Field (char *readPtr, int *hexCharsRead) +{ + char octet4Holder[4]; + u_long value; + int i; + + for (i = 0; i < 4; i++) + octet4Holder[i] = * (readPtr + i); + + *hexCharsRead = 4; + + value = 16*16*16* hexChar2int (octet4Holder[0]) + + 16*16* hexChar2int (octet4Holder[1]) + + 16* hexChar2int (octet4Holder[2]) + + hexChar2int (octet4Holder[3]); + return (value); +} + +u_long +IorHandler::getOctet2Field (char *readPtr, int *hexCharsRead) +{ + char octet2Holder[2]; + u_long value; + int i; + + for (i = 0; i < 2; i++) + octet2Holder[i] = * (readPtr + i); + + *hexCharsRead = 2; + + value = 16 * hexChar2int (octet2Holder[0]) + hexChar2int (octet2Holder[1]); + return (value); +} + +void +IorHandler::skipNullOctets (char *readPtr, int *hexCharsRead) +{ + char nullOctet[2]; + int offset; + + *hexCharsRead = 0; + offset = 0; + + // There sometimes occurs a null padding of 2 octets after strings + // such as the type_id in order to ensure even number of octets. + + while (1) + { + nullOctet[0] = * (readPtr + offset); + nullOctet[1] = * (readPtr + offset + 1); + if ((nullOctet[0] == '0') && (nullOctet[1] == '0')) + offset += 2; + else + break; + } + + *hexCharsRead = offset; +} + +char * +IorHandler::getString (char *readPtr, int givenLen) +{ + char parsedStr[MAX_IOR_FIELD_LEN]; + char octetPair[2]; + char parsedOctetPair[2]; + int intEquiv; + int i = 0; + int j = 0; + + // i indexes hexChars while j indexes octet pairs + + while (i <= (givenLen - 2)) + { + octetPair[0] = * (readPtr + i); + octetPair[1] = * (readPtr + i + 1); + + intEquiv = 16*hexChar2int (octetPair[0]) + hexChar2int (octetPair[1]); + sprintf (parsedOctetPair, "%c", intEquiv); + parsedStr[j] = parsedOctetPair[0]; + j ++; + + i += 2; + } + + return (parsedStr); +} + +void +IorHandler::prettyPrintIOR (struct IOR thisIor) +{ + ACE_DEBUG ((LM_DEBUG, + "TypeIdLen\t: %lu bytes\n", + thisIor.typeIdLen)); + ACE_DEBUG ((LM_DEBUG, + "TypeId\t\t: %s\n", + thisIor.typeId)); + ACE_DEBUG ((LM_DEBUG, + "IDL Interface\t: %s\n", + thisIor.idlInterface)); + ACE_DEBUG ((LM_DEBUG, + "ProfileBodyLen\t: %lu bytes\n", + thisIor.profileBodyLen)); + ACE_DEBUG ((LM_DEBUG, + "HostLen\t\t: %lu bytes\n", + thisIor.hostLen)); + ACE_DEBUG ((LM_DEBUG, + "HostName\t: %s\n", + thisIor.HostName)); + ACE_DEBUG ((LM_DEBUG, + "Port Number\t: %lu\n", + thisIor.portNum)); + ACE_DEBUG ((LM_DEBUG, + "ObjectKeyLen\t: %lu bytes\n", + thisIor.objectKeyLen)); + ACE_DEBUG ((LM_DEBUG, + "ObjectKey\t: %s\n", + thisIor.objectKey)); +} + +void +IorHandler::interpretIor (char *thisIor, struct IOR *thisIorInfo) +{ + int numCharsToSkip; + char nullOctet[2]; + + // Skip the prefix "IOR:" + int numHexCharsRead = 4; + + skipNullOctets ((char *) (thisIor + numHexCharsRead), &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + int ulongValue = getOctet2Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the length of the type_id field + if (ulongValue == 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: type_id len seems to be NULL \n", + numHexCharsRead)); + ACE_OS::exit (1); + } + + numHexCharsRead += numCharsToSkip; + thisIorInfo->typeIdLen = ulongValue; + + // Read the type_id and store it + ACE_OS::strncpy (thisIorInfo->typeId, + getString ((char *) (thisIor + numHexCharsRead), + 2 * thisIorInfo->typeIdLen), + thisIorInfo->typeIdLen); + numHexCharsRead += 2 * thisIorInfo->typeIdLen; + + // While we have the type_id, we may as well extract the IDL + // interface name from it. + ACE_OS::strcpy (thisIorInfo->idlInterface, + getIdlInterface (thisIorInfo->typeId)); + ACE_DEBUG ((LM_DEBUG, + "\nTypeId\t\t: %s \n", + thisIorInfo->typeId)); + ACE_DEBUG ((LM_DEBUG, + "IDL Interface\t: %s\n", + thisIorInfo->idlInterface)); + + skipNullOctets ((char *) (thisIor + numHexCharsRead), &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + ulongValue = getOctet2Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the 4 octets, which should equal 1 (numTaggedProfiles = 1) + if (ulongValue != 1) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: numTaggedProfiles != 1\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + + ulongValue = getOctet8Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the 4 octets, which should equal 0 (TAG_INTERNET_IOP = 0) + + if (ulongValue != 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: TAG_INTERNET_IOP != 0\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + + skipNullOctets ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + // Since the object_key and the hostname are part of the ProfileBody + // field of the IOR, and this is the part that needs to be changed, + // the IOR should be cut here typically if we want to fake it. + cutAndPasteHere = numHexCharsRead; + + ulongValue = getOctet2Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the 4 octets, which represent the length of the ProfileBody + if (ulongValue == 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: ProfileBody len equals NULL\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + + numHexCharsRead += numCharsToSkip; + thisIorInfo->profileBodyLen = ulongValue; + + ACE_DEBUG ((LM_DEBUG, + "\nTAG_INTERNET_IOP Profile:\n")); + + ulongValue = getOctet4Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the 4 octets, which represent the IIOP version number = 1 + if (ulongValue != 1) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: IIOP version != 1\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + + skipNullOctets ((char *) (thisIor + numHexCharsRead), &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + ulongValue = getOctet2Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the 2 octets, which represent the length of the hostname + if (ulongValue == 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: hostLen equals NULL\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + thisIorInfo->hostLen = ulongValue; + + // 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\n", + thisIorInfo->HostName)); + + skipNullOctets ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + ulongValue = getOctet4Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the port number and store it + if (ulongValue == 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: port number equals NULL\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + thisIorInfo->portNum = ulongValue; + ACE_DEBUG ((LM_DEBUG, + " Port Number: %lu\n", + thisIorInfo->portNum)); + + skipNullOctets ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + numHexCharsRead += numCharsToSkip; + + ulongValue = getOctet2Field ((char *) (thisIor + numHexCharsRead), + &numCharsToSkip); + + // Read the object key length and store it + if (ulongValue == 0) + { + ACE_DEBUG ((LM_DEBUG, + "<%d hexChars read>: objectKeyLen equals NULL\n", + numHexCharsRead)); + ACE_OS::exit (1); + } + numHexCharsRead += numCharsToSkip; + thisIorInfo->objectKeyLen = ulongValue; + + // 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 \n\n", + thisIorInfo->objectKey)); + + // Pretty print the IOR with more debugging information + // prettyPrintIOR (*thisIorInfo); +} + +char * +IorHandler::getIdlInterface (char *typeId) +{ + char idlInterface[MAX_TYPE_ID_LEN]; + int lenInterface; + + // @@ Priya, can you please avoid the use of "magic constants" like + // 58. + char *readStart = strchr (typeId, 58); + + // 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. The ASCII equivalent of ":" is 58. + + if (readStart == NULL) + { + ACE_DEBUG ((LM_DEBUG, + "getIdlInterface: type_id contains no starting :\n")); + ACE_OS::exit (1); + } + + char *readEnd = strrchr (typeId, 58); + + 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'; + + 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", + stringRealIOR); + ACE_OS::fclose (fp); + + interpretIor (stringRealIOR, &parsedRealIOR); +} diff --git a/TAO/utils/IorParser/ior-handler.h b/TAO/utils/IorParser/ior-handler.h new file mode 100644 index 00000000000..49f5c7394fd --- /dev/null +++ b/TAO/utils/IorParser/ior-handler.h @@ -0,0 +1,99 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/utils/IOR-parser +// +// = FILENAME +// ior-handler.h +// +// = DESCRIPTION +// Provides the definition of a class that parses real (valid) IORs. +// +// = AUTHORS +// Priya Narasimhan <priya@lambda.ece.ucsb.edu> +// +// ============================================================================ + +#if !defined (__IORPARSER_H__) +#define __IORPARSER_H__ + +#include "ace/OS.h" + +// Maximum length of either the type_id, the ProfileBody or the +// object_key fields. Tentatively assigned. +#define MAX_IOR_FIELD_LEN 200 +#define MAX_TYPE_ID_LEN 100 + +// These are CDR-encoed sequences of hexChars (note, not octets) that +// are useful in creating IORs +#define NULL_HEXCHARS "00000000" +#define NUM_TAG_PROFS "0001" +#define IIOP_VERSION "0001" + +class IOR +{ + // = TITLE + // This is the useful information obtained from parsing an IOR. + // + // = DESCRIPTION + // This structure assumes that the profile_id is + // TAG_INTERNET_IOP and that there is only one TaggedProfile in + // the IOR. +public: + // @@ Priya, can you please add comments to these fields? + + u_long typeIdLen; + + char typeId[MAX_TYPE_ID_LEN]; + + char idlInterface[MAX_TYPE_ID_LEN]; + + u_long profileBodyLen; + + u_long hostLen; + + char HostName[32]; + + u_long portNum; + + u_long objectKeyLen; + + char objectKey[100]; +}; + +class IorHandler +{ + // = TITLE + // This is the class that takes in a real (valid) IOR from a + // server and patches it with the Replication Manager's port + // number and IP address, while leaving the IDL interface part + // unchanged. + // + // = DESCRIPTION + // This class ensures that the Replication Manager will become + // the point of contact when a client wishes to contact the + // actual server. +public: + // @@ Priya, can you please add comments to these methods? + IorHandler (void); + void prettyPrintIOR (struct IOR thisIor); + void interpretIor (char *thisIor, struct IOR *thisIorInfo); + char *getIdlInterface (char *typeId); + void readIorFromFile (char *filename); + + int cutAndPasteHere; + char stringRealIOR[400]; + struct IOR parsedRealIOR; + +private: + int hexChar2int (char thisChar); + u_long getOctet8Field (char *readPtr, int *hexCharsRead); + u_long getOctet4Field (char *readPtr, int *hexCharsRead); + u_long getOctet2Field (char *readPtr, int *hexCharsRead); + void skipNullOctets (char *readPtr, int *hexCharsRead); + char *getString (char *readPtr, int givenLen); +}; + +#endif /* __IORPARSER_H__ */ diff --git a/TAO/utils/IorParser/ior-parser.cpp b/TAO/utils/IorParser/ior-parser.cpp new file mode 100644 index 00000000000..4162384f28b --- /dev/null +++ b/TAO/utils/IorParser/ior-parser.cpp @@ -0,0 +1,38 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/utils/IOR-parser +// +// = FILENAME +// ior-parser.cpp +// +// = DESCRIPTION +// Main loop of the IOR Parser. +// +// = AUTHORS +// Priya Narasimhan <priya@lambda.ece.ucsb.edu> +// +// ============================================================================ + +#include "iorParser.h" + +IorHandler parser; + +int +main (int argc, char **argv) +{ + if (argc <= 1 || argc >= 3) + ACE_ERROR_RETURN ((LM_ERROR, + "USAGE: parseIor <IOR filename>\n"), + 1); + + parser.readIorFromFile (argv[1]); + return 0; +} + + + + + diff --git a/TAO/utils/catior/Makefile b/TAO/utils/catior/Makefile new file mode 100644 index 00000000000..18eaedec828 --- /dev/null +++ b/TAO/utils/catior/Makefile @@ -0,0 +1,45 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for the catior utility +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif # ! TAO_ROOT + +BIN = catior + +BUILD = $(VBIN) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(TAO_ROOT)/rules.tao.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU +include $(TAO_ROOT)/taoconfig.mk + +#---------------------------------------------------------------------------- +# Local targets +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. + + + +# IF YOU PUT ANYTHING HERE IT WILL GO AWAY |