Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / EndpointPolicy / IIOPEndpointValue_i.cpp
blob54517440cd1429db1837884fb57345b5a611eb6a
1 // -*- C++ -*-
2 #include "tao/EndpointPolicy/IIOPEndpointValue_i.h"
4 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
6 #include "tao/IIOP_Endpoint.h"
7 #include "tao/IIOP_Acceptor.h"
8 #include "ace/OS_NS_strings.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 IIOPEndpointValue_i::IIOPEndpointValue_i ()
13 :host_(""),
14 port_(0)
18 IIOPEndpointValue_i::IIOPEndpointValue_i (const char *host, CORBA::UShort port)
19 :host_(host),
20 port_(port)
22 if (this->addr_.set(port, host) != 0 || host == 0 || host[0] == 0)
23 this->addr_.set_type (-1);
26 IIOPEndpointValue_i::~IIOPEndpointValue_i ()
30 CORBA::Boolean
31 IIOPEndpointValue_i::is_equivalent (const TAO_Endpoint * endpoint) const
33 const TAO_IIOP_Endpoint *iep =
34 dynamic_cast<const TAO_IIOP_Endpoint *>(endpoint);
35 if (iep == 0)
36 return 0;
37 return this->addr_.get_type() != -1 ? this->addr_ == iep->object_addr() :
38 this->is_equivalent_i (iep->port(), iep->host());
41 CORBA::Boolean
42 IIOPEndpointValue_i::is_equivalent_i (CORBA::UShort port,
43 const char *host) const
45 bool is_eq = this->port_ == port;
46 if (is_eq)
47 is_eq = (this->host_.in()[0] == '\0' ||
48 ACE_OS::strcasecmp(host, this->host_.in()) == 0);
49 return is_eq;
52 CORBA::Boolean
53 IIOPEndpointValue_i::validate_acceptor(TAO_Acceptor * acceptor,
54 bool is_multi_prot) const
56 TAO_IIOP_Acceptor *iacc = dynamic_cast<TAO_IIOP_Acceptor *>(acceptor);
57 if (iacc == 0)
58 return false;
60 #if 0
61 // @@@ mesnier_p@ociweb.com @@@
62 // This test was originally intended to validate that there is an
63 // acceptor available which supports the target endpoint. However,
64 // variablility in the definition of a "hostname" makes this hard
65 // to determine, without adding more overhead, probably to the
66 // IIOP_Acceptor class.
67 // I'm not sure this level of validation is really required, so
68 // for now I'm just leaving it out.
70 const ACE_INET_Addr * eps = iacc->endpoints ();
71 CORBA::ULong eps_count = iacc->endpoint_count ();
72 for (CORBA::ULong eps_idx = 0; eps_idx < eps_count; ++ eps_idx)
74 char hostname[513];
75 eps[eps_idx].get_host_name(hostname,512);
76 if (this->is_equivalent_i(eps[eps_idx].get_port_number(),hostname))
77 return true;
79 return false;
80 #else
81 // @@@ mesnier_p@ociweb.com @@@
82 // Rather than blindly returning true, we need to reject defaulted
83 // endpoint hosts except when the ORB has more than one protocol
84 // acceptor defined;
86 return is_multi_prot || this->host_.in()[0] != '\0';
87 #endif /* 0 */
90 char *
91 IIOPEndpointValue_i::host ()
93 return CORBA::string_dup (this->host_.in());
96 void
97 IIOPEndpointValue_i::host (const char *h)
99 this->host_ = h;
100 if (this->addr_.set(this->port_, this->host_.in ()) != 0)
101 this->addr_.set_type (-1);
104 CORBA::UShort
105 IIOPEndpointValue_i::port ()
107 return this->port_;
110 void
111 IIOPEndpointValue_i::port (CORBA::UShort p )
113 this->port_ = p;
114 if (this->addr_.set(this->port_, this->host_.in ()) != 0)
115 this->addr_.set_type (-1);
118 CORBA::ULong
119 IIOPEndpointValue_i::protocol_tag ()
121 return IOP::TAG_INTERNET_IOP;
124 TAO_END_VERSIONED_NAMESPACE_DECL
126 #endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */