ior.cc
来自「编译工具」· CC 代码 · 共 1,411 行 · 第 1/3 页
CC
1,411 行
voidomniORB::setPersistentServerIdentifier(const _CORBA_Unbounded_Sequence_Octet& id){ if (orbParameters::persistentId.length()) { // Once set, it must not be changed OMNIORB_THROW(INITIALIZE, INITIALIZE_FailedLoadLibrary, CORBA::COMPLETED_NO); } orbParameters::persistentId = id; if (omniORB::trace(10)) { logPersistentIdentifier(); }}OMNI_NAMESPACE_BEGIN(omni)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// For the TAGs that the ORB will look at, add a handler to the following// table.//static struct { IOP::ComponentId id; void (*fn)(const IOP::TaggedComponent&,omniIOR&); char* (*dump)(const IOP::TaggedComponent&);} componentUnmarshalHandlers[] = { // This table must be arranged in ascending order of IOP::ComponentId { IOP::TAG_ORB_TYPE, omniIOR::unmarshal_TAG_ORB_TYPE, omniIOR::dump_TAG_ORB_TYPE }, { IOP::TAG_CODE_SETS, omniIOR::unmarshal_TAG_CODE_SETS, omniIOR::dump_TAG_CODE_SETS }, { IOP::TAG_POLICIES, 0, 0 }, { IOP::TAG_ALTERNATE_IIOP_ADDRESS, omniIOR::unmarshal_TAG_ALTERNATE_IIOP_ADDRESS, omniIOR::dump_TAG_ALTERNATE_IIOP_ADDRESS }, { IOP::TAG_COMPLETE_OBJECT_KEY, 0, 0 }, { IOP::TAG_ENDPOINT_ID_POSITION, 0, 0 }, { IOP::TAG_LOCATION_POLICY, 0, 0 }, { IOP::TAG_ASSOCIATION_OPTIONS, 0, 0 }, { IOP::TAG_SEC_NAME, 0, 0 }, { IOP::TAG_SPKM_1_SEC_MECH, 0, 0 }, { IOP::TAG_SPKM_2_SEC_MECH, 0, 0 }, { IOP::TAG_KERBEROSV5_SEC_MECH, 0, 0 }, { IOP::TAG_CSI_ECMA_SECRET_SEC_MECH, 0, 0 }, { IOP::TAG_CSI_ECMA_HYBRID_SEC_MECH, 0, 0 }, { IOP::TAG_SSL_SEC_TRANS, omniIOR::unmarshal_TAG_SSL_SEC_TRANS, omniIOR::dump_TAG_SSL_SEC_TRANS }, { IOP::TAG_CSI_ECMA_PUBLIC_SEC_MECH, 0, 0 }, { IOP::TAG_GENERIC_SEC_MECH, 0, 0 }, { IOP::TAG_FIREWALL_TRANS, 0, 0 }, { IOP::TAG_SCCP_CONTACT_INFO, 0, 0 }, { IOP::TAG_JAVA_CODEBASE, 0, 0 }, { IOP::TAG_DCE_STRING_BINDING, 0, 0 }, { IOP::TAG_DCE_BINDING_NAME, 0, 0 }, { IOP::TAG_DCE_NO_PIPES, 0, 0 }, { IOP::TAG_DCE_SEC_MECH, 0, 0 }, { IOP::TAG_INET_SEC_TRANS, 0, 0 }, { IOP::TAG_GROUP, omniIOR::unmarshal_TAG_GROUP, omniIOR::dump_TAG_GROUP }, { IOP::TAG_PRIMARY, 0, 0 }, { IOP::TAG_HEARTBEAT_ENABLED, 0, 0 }, { IOP::TAG_OMNIORB_BIDIR, omniIOR::unmarshal_TAG_OMNIORB_BIDIR, omniIOR::dump_TAG_OMNIORB_BIDIR }, { IOP::TAG_OMNIORB_UNIX_TRANS, omniIOR::unmarshal_TAG_OMNIORB_UNIX_TRANS, omniIOR::dump_TAG_OMNIORB_UNIX_TRANS }, { IOP::TAG_OMNIORB_PERSISTENT_ID, omniIOR::unmarshal_TAG_OMNIORB_PERSISTENT_ID, omniIOR::dump_TAG_OMNIORB_PERSISTENT_ID }, { 0xffffffff, 0, 0 }};static int tablesize = 0;OMNI_NAMESPACE_END(omni)/////////////////////////////////////////////////////////////////////////////char*IOP::dumpComponent(const IOP::TaggedComponent& c) { if (!tablesize) { while (componentUnmarshalHandlers[tablesize].id != 0xffffffff) tablesize++; } int top = tablesize; int bottom = 0; do { int i = (top + bottom) >> 1; IOP::ComponentId id = componentUnmarshalHandlers[i].id; if (id == c.tag) { if (componentUnmarshalHandlers[i].dump) { return componentUnmarshalHandlers[i].dump(c); } break; } else if (id > c.tag) { top = i; } else { bottom = i + 1; } } while (top != bottom); // Reach here if we don't know how to dump the content. CORBA::ULong len = c.component_data.length() * 2 + 4; const char* tagname = IOP::ComponentIDtoName(c.tag); if (!tagname) { len += sizeof("unknown tag()") + 10; } else { len += strlen(tagname); } CORBA::String_var outstr; char* p; outstr = p = CORBA::string_alloc(len); memset(p,0,len+1); if (tagname) { strcpy(p,tagname); } else { sprintf(p,"unknown tag(0x%08lx)",(unsigned long)c.tag); } p += strlen(p); *p++ = ' '; *p++ = '0'; *p++ = 'x'; CORBA::Char* data = (CORBA::Char *) c.component_data.get_buffer(); for (CORBA::ULong i=0; i < c.component_data.length(); i++) { int v = (data[i] & 0xf0); v = v >> 4; if (v < 10) *p++ = '0' + v; else *p++ = 'a' + (v - 10); v = ((data[i] & 0xf)); if (v < 10) *p++ = '0' + v; else *p++ = 'a' + (v - 10); } return outstr._retn();}/////////////////////////////////////////////////////////////////////////////// Default interceptors ///////////////////////////////////////////////////////////////////////////////OMNI_NAMESPACE_BEGIN(omni)static IIOP::Address my_address;static _CORBA_Unbounded_Sequence_Octet my_code_set;static _CORBA_Unbounded_Sequence_Octet my_orb_type;static _CORBA_Unbounded_Sequence<_CORBA_Unbounded_Sequence_Octet> my_alternative_addr;static _CORBA_Unbounded_Sequence<_CORBA_Unbounded_Sequence_Octet> my_ssl_addr;static _CORBA_Unbounded_Sequence<_CORBA_Unbounded_Sequence_Octet> my_unix_addr;_CORBA_Unbounded_Sequence_Octet orbParameters::persistentId;OMNI_NAMESPACE_END(omni)/////////////////////////////////////////////////////////////////////////////voidomniIOR::add_IIOP_ADDRESS(const IIOP::Address& address) { if (my_address.port == 0) { my_address = address; } else { add_TAG_ALTERNATE_IIOP_ADDRESS(address); }}/////////////////////////////////////////////////////////////////////////////voidomniIOR::add_TAG_CODE_SETS(const CONV_FRAME::CodeSetComponentInfo& info) { cdrEncapsulationStream s(CORBA::ULong(0),CORBA::Boolean(1)); info >>= s; CORBA::Octet* p; CORBA::ULong max,len; s.getOctetStream(p,max,len); my_code_set.replace(max,len,p,1);}/////////////////////////////////////////////////////////////////////////////voidomniIOR::add_TAG_ALTERNATE_IIOP_ADDRESS(const IIOP::Address& address) { cdrEncapsulationStream s(CORBA::ULong(0),CORBA::Boolean(1)); s.marshalRawString(address.host); address.port >>= s; CORBA::ULong index = my_alternative_addr.length(); my_alternative_addr.length(index+1); CORBA::Octet* p; CORBA::ULong max,len; s.getOctetStream(p,max,len); my_alternative_addr[index].replace(max,len,p,1);}/////////////////////////////////////////////////////////////////////////////voidomniIOR::add_TAG_SSL_SEC_TRANS(const IIOP::Address& address, CORBA::UShort supports,CORBA::UShort requires) { if (strlen(my_address.host) == 0) { my_address.host = address.host; } else if (strcmp(my_address.host,address.host) != 0) { // The address does not match. We cannot add this address to our IOR. // Shouldn't have happened! omniORB::logger log; log << "Warning: cannot add this SSL address (" << address.host << "," << address.port << ") to the IOR because the host name does not match my host name (" << my_address.host << ")\n"; return; } cdrEncapsulationStream s(CORBA::ULong(0),CORBA::Boolean(1)); supports >>= s; requires >>= s; address.port >>= s; CORBA::ULong index = my_ssl_addr.length(); my_ssl_addr.length(index+1); CORBA::Octet* p; CORBA::ULong max,len; s.getOctetStream(p,max,len); my_ssl_addr[index].replace(max,len,p,1);}/////////////////////////////////////////////////////////////////////////////voidomniIOR::add_TAG_OMNIORB_UNIX_TRANS(const char* filename) { OMNIORB_ASSERT(filename && strlen(filename) != 0); char self[64]; if (gethostname(&self[0],64) == RC_SOCKET_ERROR) { omniORB::logs(1, "Cannot get the name of this host."); self[0] = '\0'; } if (strlen(my_address.host) == 0) { my_address.host = (const char*) self; } cdrEncapsulationStream s(CORBA::ULong(0),CORBA::Boolean(1)); s.marshalRawString(self); s.marshalRawString(filename); CORBA::ULong index = my_unix_addr.length(); my_unix_addr.length(index+1); CORBA::Octet* p; CORBA::ULong max,len; s.getOctetStream(p,max,len); my_unix_addr[index].replace(max,len,p,1);}OMNI_NAMESPACE_BEGIN(omni)/////////////////////////////////////////////////////////////////////////////staticCORBA::Boolean insertSupportedComponents(omniInterceptors::encodeIOR_T::info_T& info){ const GIOP::Version& v = info.iiop.version; IOP::MultipleComponentProfile& cs = info.iiop.components; if (strlen(info.iiop.address.host) == 0) { if (strlen(my_address.host) == 0) { OMNIORB_THROW(MARSHAL,MARSHAL_InvalidIOR,CORBA::COMPLETED_NO); } info.iiop.address = my_address; } if ((v.major > 1 || v.minor >= 1) && my_orb_type.length()) { // 1.1 or later, Insert ORB TYPE IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_ORB_TYPE; CORBA::ULong max, len; max = my_orb_type.maximum(); len = my_orb_type.length(); c.component_data.replace(max,len,my_orb_type.get_buffer(),0); } if ((v.major > 1 || v.minor >= 2) && my_code_set.length()) { // 1.2 or later, Insert CODE SET IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_CODE_SETS; CORBA::ULong max, len; max = my_code_set.maximum(); len = my_code_set.length(); c.component_data.replace(max,len,my_code_set.get_buffer(),0); } if (v.major > 1 || v.minor >= 2) { // 1.2 or later, Insert ALTERNATIVE IIOP ADDRESS for (CORBA::ULong index = 0; index < my_alternative_addr.length(); index++) { IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_ALTERNATE_IIOP_ADDRESS; CORBA::ULong max, len; max = my_alternative_addr[index].maximum(); len = my_alternative_addr[index].length(); c.component_data.replace(max,len, my_alternative_addr[index].get_buffer(),0); } } if (v.major > 1 || v.minor >= 1) { // 1.1 or later, Insert SSL_SEC_TRANS for (CORBA::ULong index = 0; index < my_ssl_addr.length(); index++) { IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_SSL_SEC_TRANS; CORBA::ULong max, len; max = my_ssl_addr[index].maximum(); len = my_ssl_addr[index].length(); c.component_data.replace(max,len, my_ssl_addr[index].get_buffer(),0); } } if (v.major > 1 || v.minor >= 2) { // 1.2 or later, Insert omniORB unix transport for (CORBA::ULong index = 0; index < my_unix_addr.length(); index++) { IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_OMNIORB_UNIX_TRANS; CORBA::ULong max, len; max = my_unix_addr[index].maximum(); len = my_unix_addr[index].length(); c.component_data.replace(max,len, my_unix_addr[index].get_buffer(),0); } } if (v.major > 1 || v.minor >= 1) { // 1.1 or later, insert omniORB persistent id if (orbParameters::persistentId.length()) { IOP::TaggedComponent& c = omniIOR::newIIOPtaggedComponent(cs); c.tag = IOP::TAG_OMNIORB_PERSISTENT_ID; c.component_data.replace(orbParameters::persistentId.maximum(), orbParameters::persistentId.length(), orbParameters::persistentId.get_buffer(), 0); } } return (info.default_only ? 0 : 1);}/////////////////////////////////////////////////////////////////////////////staticCORBA::Boolean extractSupportedComponents(omniInterceptors::decodeIOR_T::info_T& info){ if (!info.has_iiop_body) return 1; omniIOR::IORInfo& iorInfo = *(info.ior.getIORInfo()); iorInfo.version(info.iiop.version); giopAddress* address = giopAddress::fromTcpAddress(info.iiop.address); if (address) iorInfo.addresses().push_back(address); if (!tablesize) { while (componentUnmarshalHandlers[tablesize].id != 0xffffffff) tablesize++; } const IOP::MultipleComponentProfile& components = info.iiop.components; CORBA::ULong total = components.length(); for (CORBA::ULong index = 0; index < total; index++) { int top = tablesize; int bottom = 0; do { int i = (top + bottom) >> 1; IOP::ComponentId id = componentUnmarshalHandlers[i].id; if (id == components[index].tag) { if (componentUnmarshalHandlers[i].fn) { componentUnmarshalHandlers[i].fn(components[index],info.ior); } break; } else if (id > components[index].tag) { top = i; } else { bottom = i + 1; } } while (top != bottom); } return 1;}/////////////////////////////////////////////////////////////////////////////// Module initialiser ///////////////////////////////////////////////////////////////////////////////class omni_ior_initialiser : public omniInitialiser {public: omni_ior_initialiser() {} void attach() { my_address.port = 0; omniORB::getInterceptors()->encodeIOR.add(insertSupportedComponents); omniORB::getInterceptors()->decodeIOR.add(extractSupportedComponents); cdrEncapsulationStream s(8,1); omniORB_TAG_ORB_TYPE >>= s; _CORBA_Octet* p; CORBA::ULong max,len; s.getOctetStream(p,max,len); my_orb_type.replace(max,len,p,1); if (omniORB::trace(10) && orbParameters::persistentId.length()) { logPersistentIdentifier(); } } void detach() { omniORB::getInterceptors()->encodeIOR.remove(insertSupportedComponents); omniORB::getInterceptors()->decodeIOR.remove(extractSupportedComponents); _CORBA_Unbounded_Sequence_Octet::freebuf(my_orb_type.get_buffer(1)); }};static omni_ior_initialiser initialiser;omniInitialiser& omni_ior_initialiser_ = initialiser;OMNI_NAMESPACE_END(omni)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?