diff options
author | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2009-11-20 14:54:40 +0000 |
commit | 84adefa331c4159d432d22840663c38f155cd4c1 (patch) | |
tree | bff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/orber/c_src | |
download | otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2 otp-84adefa331c4159d432d22840663c38f155cd4c1.zip |
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/orber/c_src')
-rw-r--r-- | lib/orber/c_src/InitialReference.cc | 205 | ||||
-rw-r--r-- | lib/orber/c_src/InitialReference.hh | 59 | ||||
-rw-r--r-- | lib/orber/c_src/Makefile | 23 | ||||
-rw-r--r-- | lib/orber/c_src/Makefile.in | 113 | ||||
-rw-r--r-- | lib/orber/c_src/main.cc | 31 |
5 files changed, 431 insertions, 0 deletions
diff --git a/lib/orber/c_src/InitialReference.cc b/lib/orber/c_src/InitialReference.cc new file mode 100644 index 0000000000..a95fa0f599 --- /dev/null +++ b/lib/orber/c_src/InitialReference.cc @@ -0,0 +1,205 @@ +/** + *<copyright> + * <year>1997-2007</year> + * <holder>Ericsson AB, All Rights Reserved</holder> + *</copyright> + *<legalnotice> + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Ericsson AB. + *</legalnotice> + */ +/** + * InitialReference is a class which generates the INIT reference + * which can be used by the InitialReferences interface. + * + * creation date: 1997-11-04 + */ +#include "InitialReference.hh" + +InitialReference::InitialReference() +{ + host = 0; + iorString = 0; +}; + +InitialReference::~InitialReference() +{ + if(host){ + delete host; + delete iorString; + } +}; + + /** + * Returns the stringified objectreference to the initial reference server + */ +char* InitialReference::stringified_ior(char* newhost, int newport) +{ + STRINGSTREAM iorByteString; + STRINGSTREAM profileData; + + STRINGBUF *s; + STRINGBUF *profileDataBuf; + STRINGBUF *iorByteStringBuf; + long profileDataLength = 0; + char *str; + + // byte_order followed by ' {"", [{0, ' + // char iorBytesFirstPart[] = {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0}; + char iorBytesFirstPart[48] = {0,0,0,0,0,0,0,32,73,68,76,58,79,114,98,101,114,47,73,110,105,116,105,97,108,82,101,102,101,114,101,110,99,101,115,58,49,46,48,0,0,0,0,1,0,0,0,0}; + // the objectkey "INIT + char iorBytesLastPart[8] = {0,0,0,4,73,78,73,84}; + + // Fix the ProfileData struct. + char pdPrefix[4] = {0,1,0,0}; + char hsize[4]; + char profileDataLengthBytes[4]; + char portbytes[2]; + long hostLength = strlen(newhost); + + + if(host) + if(strcmp(newhost, host) == 0 && newport == port) + return iorString; + else { + delete host; + delete iorString; + } + host = new char[hostLength+1]; + memcpy(host, newhost, hostLength+1); + port = newport; + + enc_ulong(hostLength + 1, hsize); + enc_ushort(port, portbytes); + + profileDataBuf = profileData.rdbuf(); + + profileDataBuf->sputn(pdPrefix, 4); + profileDataBuf->sputn(hsize, 4); + profileDataBuf->sputn(host, hostLength); + profileDataBuf->sputc(0); + profileDataLength = 4 + 4 + hostLength + 1; + + profileDataLength = align(profileDataBuf, profileDataLength, 2); + + profileDataBuf->sputn(portbytes, 2); + profileDataLength += 2; + + profileDataLength = align(profileDataBuf, profileDataLength, 4); + + profileDataBuf->sputn(iorBytesLastPart, 8); + profileDataLength += 8; + //cout << "pd length: " << profileDataLength << "\n"; + + enc_ulong(profileDataLength, profileDataLengthBytes); + + // Fix the whole IOR + + iorByteStringBuf = iorByteString.rdbuf(); + + iorByteStringBuf->sputn(iorBytesFirstPart, 48); + iorByteStringBuf->sputn(profileDataLengthBytes, 4); +#ifdef HAVE_SSTREAM + iorByteStringBuf->sputn(profileData.str().data(), profileDataLength); +#else + str = profileData.str(); + iorByteStringBuf->sputn(str, profileDataLength); + delete str; +#endif + + createIOR(iorByteString, 48 + 4 + profileDataLength); + + return iorString; +} + + +void InitialReference::enc_ushort(int s, char *byteArray) +{ + byteArray[0] = (char) ((s >> 8) & 0xFF); + byteArray[1] = (char) ((s >> 0) & 0xFF); + + return; +} + +void InitialReference::enc_ulong(long l, char *byteArray) +{ + byteArray[0] = (char) ((l >> 24) & 0xFF); + byteArray[1] = (char) ((l >> 16) & 0xFF); + byteArray[2] = (char) ((l >> 8) & 0xFF); + byteArray[3] = (char) ((l >> 0) & 0xFF); + + return; +} + +void InitialReference::createIOR(strstream& byte, long length) +{ + STRINGBUF *stringbuf; + STRINGSTREAM string; + + int i; +#ifdef HAVE_SSTREAM + const char *c; + const char *bytestr = byte.str().c_str(); +#else + char *c; + char *bytestr = byte.str(); +#endif + int b, n1, n2, c1, c2; + + stringbuf = string.rdbuf(); + stringbuf->sputn("IOR:",4); + + for(i = 0, c = bytestr; i < length; c++, i++) + { + b = *c; + if(b<0) b+= 256; + n1 = b / 16; + n2 = b % 16; + c1 = (n1 < 10) ? ('0' + n1) : ('a' + (n1 - 10)); + c2 = (n2 < 10) ? ('0' + n2) : ('a' + (n2 - 10)); + + stringbuf->sputc(c1); + stringbuf->sputc(c2); + + } + + stringbuf->sputc(0); + + delete bytestr; + +#ifdef HAVE_SSTREAM + iorString = (char *)string.str().c_str(); +#else + iorString = string.str(); +#endif + + return; +} + +long InitialReference::align(STRINGBUF* sbuf, long currentLength, + int alignment) +{ + long length = currentLength; + + int remainder = alignment - (currentLength % alignment); + if (remainder == alignment) return length; + + for (int i = 0; i < remainder; i++) + { + sbuf->sputc(0); + length++; + } + return length; +} + + diff --git a/lib/orber/c_src/InitialReference.hh b/lib/orber/c_src/InitialReference.hh new file mode 100644 index 0000000000..1c3c5c8e0d --- /dev/null +++ b/lib/orber/c_src/InitialReference.hh @@ -0,0 +1,59 @@ +/** + *<copyright> + * <year>1997-2007</year> + * <holder>Ericsson AB, All Rights Reserved</holder> + *</copyright> + *<legalnotice> + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Ericsson AB. + *</legalnotice> + */ +/* + * InitialReference is a class for creating an external IOR for the object + * reference INIT. + */ +#ifndef _INITIALREFERENCE_HH +#define _INITIALREFERENCE_HH +#include <stdio.h> +#include <string.h> + +#if HAVE_SSTREAM +#include <sstream> +typedef std::stringstream STRINGSTREAM; +typedef std::stringbuf STRINGBUF; +#else +#include <strstream.h> +typedef strstream STRINGSTREAM; +typedef strstreambuf STRINGBUF; +#endif + +class InitialReference { +private: + char* iorString; + char* host; + int port; + + void enc_ushort(int s, char *byteArray); + void enc_ulong(long l, char *byteArray); + void createIOR(STRINGSTREAM& byte, long length); + long align(STRINGBUF* sbuf, long currentLength, int alignment); + +public: + InitialReference(); + ~InitialReference(); + + char* stringified_ior(char* host, int port); + +}; + +#endif diff --git a/lib/orber/c_src/Makefile b/lib/orber/c_src/Makefile new file mode 100644 index 0000000000..73ab79d145 --- /dev/null +++ b/lib/orber/c_src/Makefile @@ -0,0 +1,23 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 1997-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +# +# Invoke with GNU make or clearmake -C gnu. +# + +include $(ERL_TOP)/make/run_make.mk diff --git a/lib/orber/c_src/Makefile.in b/lib/orber/c_src/Makefile.in new file mode 100644 index 0000000000..56f0d57545 --- /dev/null +++ b/lib/orber/c_src/Makefile.in @@ -0,0 +1,113 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 1997-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +CXX = @CXX@ +CC = @CC@ +LIBS = @LIBS@ + +OBJDIR = ../priv/obj/$(TARGET) + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../vsn.mk +VSN=$(ORBER_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/orber-$(VSN) + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- +CC_FILES = \ + InitialReference.cc + +HH_FILES = \ + InitialReference.hh + +ALL_CFLAGS = @CFLAGS@ @DEFS@ $(CFLAGS) + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- + +debug opt: $(OBJDIR) orber + +ifeq ($(findstring win32,$(TARGET)),win32) +orber: + echo "Nothing to build on NT" +else +ifeq ($(findstring vxworks,$(TARGET)),vxworks) +orber: + echo "Nothing to build for VxWorks" + +else +orber: + echo "Nothing to build" +endif +endif + +clean: + +docs: + +# ---------------------------------------------------- +# Special Build Targets +# ---------------------------------------------------- + +$(OBJDIR): + -mkdir -p $(OBJDIR) + +$(OBJDIR)/%.o: %.c + $(CC) -c -o $@ $(ALL_CFLAGS) $< + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + +ifeq ($(findstring win32,$(TARGET)),win32) +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/priv/src + $(INSTALL_DIR) $(RELSYSDIR)/priv/include + $(INSTALL_PROGRAM) $(CC_FILES) $(RELSYSDIR)/priv/src + $(INSTALL_PROGRAM) $(HH_FILES) $(RELSYSDIR)/priv/include +else +ifeq ($(findstring vxworks,$(TARGET)),vxworks) +release_spec: + $(INSTALL_DIR) $(RELSYSDIR)/priv/src + $(INSTALL_DIR) $(RELSYSDIR)/priv/include + $(INSTALL_PROGRAM) $(CC_FILES) $(RELSYSDIR)/priv/src + $(INSTALL_PROGRAM) $(HH_FILES) $(RELSYSDIR)/priv/include +else +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/priv/src + $(INSTALL_DIR) $(RELSYSDIR)/priv/include + $(INSTALL_DATA) $(CC_FILES) $(RELSYSDIR)/priv/src + $(INSTALL_DATA) $(HH_FILES) $(RELSYSDIR)/priv/include +endif +endif + + +release_docs_spec: diff --git a/lib/orber/c_src/main.cc b/lib/orber/c_src/main.cc new file mode 100644 index 0000000000..c1d17078c5 --- /dev/null +++ b/lib/orber/c_src/main.cc @@ -0,0 +1,31 @@ +/** + *<copyright> + * <year>1997-2007</year> + * <holder>Ericsson AB, All Rights Reserved</holder> + *</copyright> + *<legalnotice> + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Ericsson AB. + *</legalnotice> + */ + +#include "InitialReference.hh" + +main() +{ + InitialReference ir; + + cout << ir.stringified_ior("fingolfin", 4001) << "\n"; + + +} |