00001 #include "tao/Strategies/SCIOP_Acceptor.h"
00002 #include "tao/Strategies/SCIOP_Profile.h"
00003
00004 #if TAO_HAS_SCIOP == 1
00005
00006 #include "tao/MProfile.h"
00007 #include "tao/debug.h"
00008 #include "tao/Protocols_Hooks.h"
00009 #include "tao/Codeset_Manager.h"
00010 #include "tao/Transport.h"
00011 #include "tao/CDR.h"
00012
00013 #if !defined(__ACE_INLINE__)
00014 #include "tao/Strategies/SCIOP_Acceptor.i"
00015 #endif
00016
00017 ACE_RCSID(tao,
00018 SCIOP_Acceptor,
00019 "SCIOP_Acceptor.cpp,v 1.15 2006/04/19 11:38:50 jwillemsen Exp")
00020
00021
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023
00024 TAO_SCIOP_Acceptor::TAO_SCIOP_Acceptor (CORBA::Boolean flag)
00025 : TAO_Acceptor (TAO_TAG_SCIOP_PROFILE),
00026 addrs_ (0),
00027 port_span_ (1),
00028 hosts_ (0),
00029 endpoint_count_ (0),
00030 hostname_in_ior_ (0),
00031 version_ (TAO_DEF_SCIOP_MAJOR, TAO_DEF_SCIOP_MINOR),
00032 orb_core_ (0),
00033 lite_flag_ (flag),
00034 base_acceptor_ (),
00035 creation_strategy_ (0),
00036 concurrency_strategy_ (0),
00037 accept_strategy_ (0)
00038 {
00039 }
00040
00041 TAO_SCIOP_Acceptor::~TAO_SCIOP_Acceptor (void)
00042 {
00043
00044
00045 this->close ();
00046
00047 delete this->creation_strategy_;
00048 delete this->concurrency_strategy_;
00049 delete this->accept_strategy_;
00050
00051 delete [] this->addrs_;
00052
00053 for (CORBA::ULong i = 0; i < this->endpoint_count_; ++i)
00054 CORBA::string_free (this->hosts_[i]);
00055
00056 delete [] this->hosts_;
00057 }
00058
00059
00060
00061 int
00062 TAO_SCIOP_Acceptor::create_profile (const TAO::ObjectKey &object_key,
00063 TAO_MProfile &mprofile,
00064 CORBA::Short priority)
00065 {
00066
00067 if (this->endpoint_count_ == 0)
00068 return -1;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 return this->create_shared_profile (object_key,
00080 mprofile,
00081 priority);
00082 }
00083
00084 int
00085 TAO_SCIOP_Acceptor::create_new_profile (const TAO::ObjectKey &object_key,
00086 TAO_MProfile &mprofile,
00087 CORBA::Short priority)
00088 {
00089
00090 int const count = mprofile.profile_count ();
00091 if ((mprofile.size () - count) < this->endpoint_count_
00092 && mprofile.grow (count + this->endpoint_count_) == -1)
00093 return -1;
00094
00095
00096 for (CORBA::ULong i = 0; i < this->endpoint_count_; ++i)
00097 {
00098 TAO_SCIOP_Profile *pfile = 0;
00099 ACE_NEW_RETURN (pfile,
00100 TAO_SCIOP_Profile (this->hosts_[i],
00101 this->addrs_[i].get_port_number (),
00102 object_key,
00103 this->addrs_[i],
00104 this->version_,
00105 this->orb_core_),
00106 -1);
00107 pfile->endpoint ()->priority (priority);
00108
00109 if (mprofile.give_profile (pfile) == -1)
00110 {
00111 pfile->_decr_refcnt ();
00112 pfile = 0;
00113 return -1;
00114 }
00115
00116 pfile->tagged_components ().set_orb_type (TAO_ORB_TYPE);
00117
00118 TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager();
00119 if (csm)
00120 csm->set_codeset(pfile->tagged_components());
00121 }
00122
00123 return 0;
00124 }
00125
00126 int
00127 TAO_SCIOP_Acceptor::create_shared_profile (const TAO::ObjectKey &object_key,
00128 TAO_MProfile &mprofile,
00129 CORBA::Short priority)
00130 {
00131 CORBA::ULong index = 0;
00132 TAO_SCIOP_Profile *sciop_profile = 0;
00133
00134
00135
00136
00137 {
00138 ACE_NEW_RETURN (sciop_profile,
00139 TAO_SCIOP_Profile (this->hosts_[0],
00140 this->addrs_[0].get_port_number (),
00141 object_key,
00142 this->addrs_[0],
00143 this->version_,
00144 this->orb_core_),
00145 -1);
00146 sciop_profile->endpoint ()->priority (priority);
00147
00148 if (mprofile.give_profile (sciop_profile) == -1)
00149 {
00150 sciop_profile->_decr_refcnt ();
00151 sciop_profile = 0;
00152 return -1;
00153 }
00154
00155 sciop_profile->tagged_components ().set_orb_type (TAO_ORB_TYPE);
00156
00157 TAO_Codeset_Manager *csm = this->orb_core_->codeset_manager();
00158 if (csm)
00159 csm->set_codeset(sciop_profile->tagged_components());
00160
00161 index = 1;
00162 }
00163
00164
00165 for (;
00166 index < this->endpoint_count_;
00167 ++index)
00168 {
00169 TAO_SCIOP_Endpoint *endpoint = 0;
00170 ACE_NEW_RETURN (endpoint,
00171 TAO_SCIOP_Endpoint (this->hosts_[index],
00172 this->addrs_[index].get_port_number (),
00173 this->addrs_[index]),
00174 -1);
00175 endpoint->priority (priority);
00176 sciop_profile->add_endpoint (endpoint);
00177 }
00178
00179 return 0;
00180 }
00181
00182 int
00183 TAO_SCIOP_Acceptor::is_collocated (const TAO_Endpoint *endpoint)
00184 {
00185 const TAO_SCIOP_Endpoint *endp =
00186 dynamic_cast<const TAO_SCIOP_Endpoint *> (endpoint);
00187
00188
00189 if (endp == 0)
00190 return 0;
00191
00192 for (CORBA::ULong i = 0; i < this->endpoint_count_; ++i)
00193 {
00194
00195
00196
00197
00198
00199
00200 if (endp->port() == this->addrs_[i].get_port_number()
00201 && ACE_OS::strcmp(endp->host(), this->hosts_[i]) == 0)
00202 return 1;
00203 }
00204
00205 return 0;
00206 }
00207
00208 int
00209 TAO_SCIOP_Acceptor::close (void)
00210 {
00211 return this->base_acceptor_.close ();
00212 }
00213
00214 int
00215 TAO_SCIOP_Acceptor::open (TAO_ORB_Core *orb_core,
00216 ACE_Reactor *reactor,
00217 int major,
00218 int minor,
00219 const char *address,
00220 const char *options)
00221 {
00222
00223 this->orb_core_ = orb_core;
00224
00225 if (this->hosts_ != 0)
00226 {
00227
00228
00229 ACE_ERROR_RETURN ((LM_ERROR,
00230 ACE_TEXT ("TAO (%P|%t) - ")
00231 ACE_TEXT ("SCIOP_Acceptor::open, ")
00232 ACE_TEXT ("hostname already set\n\n")),
00233 -1);
00234 }
00235
00236 if (address == 0)
00237 return -1;
00238
00239 ACE_UNUSED_ARG (major);
00240 ACE_UNUSED_ARG (minor);
00241
00242
00243 if (this->parse_options (options) == -1)
00244 return -1;
00245
00246 ACE_Multihomed_INET_Addr addr;
00247
00248 const char *port_separator_loc = ACE_OS::strchr (address, ':');
00249 ACE_Auto_Basic_Array_Ptr<char> tmp_host_auto;
00250
00251 if (port_separator_loc == address)
00252 {
00253
00254
00255
00256
00257
00258 if (this->probe_interfaces (orb_core) == -1)
00259 return -1;
00260
00261
00262 ACE_INET_Addr temp_addr;
00263 if (temp_addr.set (address + sizeof (':')) != 0)
00264 return -1;
00265
00266
00267 if (addr.set (temp_addr.get_port_number (),
00268 static_cast<ACE_UINT32> (INADDR_ANY),
00269 1) != 0)
00270 return -1;
00271 else
00272 return this->open_i (addr,
00273 reactor);
00274 }
00275
00276
00277
00278
00279 u_short port_number = 0;
00280 char *tmp_host = 0;
00281 size_t hostname_length = 0;
00282
00283 if (port_separator_loc != 0) {
00284
00285
00286
00287 const char *port_loc = port_separator_loc;
00288 ++port_loc;
00289 if (port_loc == 0) {
00290 ACE_ERROR_RETURN ((LM_ERROR,
00291 ACE_TEXT ("TAO (%P|%t) ")
00292 ACE_TEXT ("SCIOP_Acceptor::open - ")
00293 ACE_TEXT ("no port number after the ")
00294 ACE_TEXT ("colon in \"%s\"\n"),
00295 address),
00296 -1);
00297 }
00298
00299
00300 ACE_INET_Addr temp_addr;
00301 if (temp_addr.string_to_addr(port_loc) != 0)
00302 return -1;
00303 port_number = temp_addr.get_port_number();
00304
00305
00306 hostname_length = port_separator_loc - address;
00307
00308 } else {
00309
00310
00311
00312
00313
00314
00315 hostname_length = ACE_OS::strlen(address);
00316 }
00317
00318 ACE_NEW_RETURN(tmp_host, char[hostname_length + 1], -1);
00319 tmp_host_auto.reset(tmp_host);
00320 ACE_OS::memcpy (tmp_host, address, hostname_length);
00321 tmp_host[hostname_length] = '\0';
00322
00323
00324 ACE_Array<ACE_CString> hostnames;
00325 if (parse_multiple_hostnames(tmp_host, hostnames) != 0)
00326 return -1;
00327
00328
00329 if (hostnames.size() < 1) {
00330 ACE_ERROR_RETURN ((LM_ERROR,
00331 ACE_TEXT ("TAO (%P|%t) ")
00332 ACE_TEXT ("SCIOP_Acceptor::open - ")
00333 ACE_TEXT ("no hostnames in string \"%s\"\n"),
00334 tmp_host),
00335 -1);
00336 }
00337
00338
00339 ACE_UINT32 primary_ip_addr = 0;
00340 {
00341
00342 ACE_CString & primary_hostname_obj = hostnames[0];
00343 ACE_Auto_Basic_Array_Ptr<char> primary_hostname_auto(primary_hostname_obj.rep());
00344 const char* primary_hostname = primary_hostname_auto.get();
00345
00346
00347 ACE_INET_Addr temp_addr;
00348 if (temp_addr.set((u_short) 0, primary_hostname) != 0)
00349 return -1;
00350
00351 primary_ip_addr = temp_addr.get_ip_address();
00352 }
00353
00354
00355 ACE_UINT32 *secondary_ip_addrs = 0;
00356 ACE_Auto_Basic_Array_Ptr<ACE_UINT32> secondary_ip_addrs_auto;
00357 size_t num_secondary_ip_addrs = hostnames.size() - 1;
00358 if (num_secondary_ip_addrs > 0) {
00359 ACE_NEW_RETURN(secondary_ip_addrs,
00360 ACE_UINT32[num_secondary_ip_addrs],
00361 -1);
00362 secondary_ip_addrs_auto.reset(secondary_ip_addrs);
00363 }
00364
00365
00366 size_t i = 0;
00367 ACE_INET_Addr temp_addr;
00368 while (i < num_secondary_ip_addrs) {
00369
00370
00371 ACE_CString & hostname_obj = hostnames[i + 1];
00372 ACE_Auto_Basic_Array_Ptr<char> hostname_auto(hostname_obj.rep());
00373 const char* hostname = hostname_auto.get();
00374
00375
00376 if (temp_addr.set((u_short) 0, hostname) != 0)
00377 return -1;
00378
00379
00380 secondary_ip_addrs[i++] = temp_addr.get_ip_address();
00381 }
00382
00383
00384
00385 if (addr.set(port_number,
00386 primary_ip_addr,
00387 1,
00388 secondary_ip_addrs,
00389 num_secondary_ip_addrs));
00390
00391
00392 this->endpoint_count_ = hostnames.size();
00393
00394 ACE_NEW_RETURN (this->addrs_,
00395 ACE_INET_Addr[this->endpoint_count_],
00396 -1);
00397
00398 ACE_NEW_RETURN (this->hosts_,
00399 char *[this->endpoint_count_],
00400 -1);
00401
00402
00403
00404 this->addrs_[0].set (addr);
00405
00406
00407
00408 ACE_INET_Addr *secondary_addrs = this->addrs_;
00409 ++secondary_addrs;
00410 addr.get_secondary_addresses(secondary_addrs, num_secondary_ip_addrs);
00411
00412
00413 i = 0;
00414 while (i < hostnames.size()) {
00415
00416
00417 if (this->hostname_in_ior_ != 0 && i == 0)
00418 {
00419 if (TAO_debug_level > 2)
00420 {
00421 ACE_DEBUG ((LM_DEBUG,
00422 ACE_TEXT ("Overriding address in IOR with %s\n"),
00423 this->hostname_in_ior_));
00424 }
00425 if (this->hostname (orb_core,
00426 this->addrs_[i],
00427 this->hosts_[i],
00428 this->hostname_in_ior_) != 0)
00429 return -1;
00430 }
00431 else
00432 {
00433
00434 ACE_CString & hostname_obj = hostnames[i];
00435 ACE_Auto_Basic_Array_Ptr<char> hostname_auto(hostname_obj.rep());
00436 const char* hostname = hostname_auto.get();
00437
00438 if (this->hostname (orb_core,
00439 this->addrs_[i],
00440 this->hosts_[i],
00441 hostname) != 0)
00442 return -1;
00443 }
00444
00445 ++i;
00446 }
00447
00448
00449 return this->open_i (addr,
00450 reactor);
00451 }
00452
00453 int
00454 TAO_SCIOP_Acceptor::open_default (TAO_ORB_Core *orb_core,
00455 ACE_Reactor *reactor,
00456 int major,
00457 int minor,
00458 const char *options)
00459 {
00460 this->orb_core_ = orb_core;
00461
00462 if (this->hosts_ != 0)
00463 {
00464
00465
00466 ACE_ERROR_RETURN ((LM_ERROR,
00467 ACE_TEXT ("TAO (%P|%t) ")
00468 ACE_TEXT ("SCIOP_Acceptor::open_default - ")
00469 ACE_TEXT ("hostname already set\n\n")),
00470 -1);
00471 }
00472
00473
00474 ACE_UNUSED_ARG (major);
00475 ACE_UNUSED_ARG (minor);
00476
00477
00478 if (this->parse_options (options) == -1)
00479 return -1;
00480
00481
00482 if (this->probe_interfaces (orb_core) == -1)
00483 return -1;
00484
00485
00486
00487
00488 ACE_Multihomed_INET_Addr addr;
00489
00490 if (addr.set (static_cast<u_short> (0),
00491 static_cast<ACE_UINT32> (INADDR_ANY),
00492 1) != 0)
00493 return -1;
00494
00495 return this->open_i (addr,
00496 reactor);
00497 }
00498
00499 int
00500 TAO_SCIOP_Acceptor::open_i (const ACE_Multihomed_INET_Addr& addr,
00501 ACE_Reactor *reactor)
00502 {
00503 ACE_NEW_RETURN (this->creation_strategy_,
00504 TAO_SCIOP_CREATION_STRATEGY (this->orb_core_,
00505 this->lite_flag_),
00506 -1);
00507
00508 ACE_NEW_RETURN (this->concurrency_strategy_,
00509 TAO_SCIOP_CONCURRENCY_STRATEGY (this->orb_core_),
00510 -1);
00511
00512 ACE_NEW_RETURN (this->accept_strategy_,
00513 TAO_SCIOP_ACCEPT_STRATEGY (this->orb_core_),
00514 -1);
00515
00516 u_short requested_port = addr.get_port_number ();
00517 if (requested_port == 0)
00518 {
00519
00520 if (this->base_acceptor_.open (addr,
00521 reactor,
00522 this->creation_strategy_,
00523 this->accept_strategy_,
00524 this->concurrency_strategy_) == -1)
00525 {
00526 if (TAO_debug_level > 0)
00527 ACE_DEBUG ((LM_DEBUG,
00528 ACE_TEXT ("\n\nTAO (%P|%t) SCIOP_Acceptor::open_i ")
00529 ACE_TEXT ("- %p\n\n"),
00530 ACE_TEXT ("cannot open acceptor")));
00531 return -1;
00532 }
00533 }
00534 else
00535 {
00536 ACE_Multihomed_INET_Addr a(addr);
00537
00538 int found_a_port = 0;
00539 ACE_UINT32 last_port = requested_port + this->port_span_ - 1;
00540 if (last_port > ACE_MAX_DEFAULT_PORT)
00541 {
00542 last_port = ACE_MAX_DEFAULT_PORT;
00543 }
00544
00545 for (ACE_UINT32 p = requested_port; p <= last_port; p++)
00546 {
00547 if (TAO_debug_level > 5)
00548 ACE_DEBUG ((LM_DEBUG,
00549 ACE_TEXT ("TAO (%P|%t) SCIOP_Acceptor::open_i() ")
00550 ACE_TEXT ("trying to listen on port %d\n"), p));
00551
00552
00553 a.set_port_number ((u_short)p);
00554 if (this->base_acceptor_.open (a,
00555 reactor,
00556 this->creation_strategy_,
00557 this->accept_strategy_,
00558 this->concurrency_strategy_) != -1)
00559 {
00560 found_a_port = 1;
00561 break;
00562 }
00563 }
00564
00565
00566 if (! found_a_port)
00567 {
00568 if (TAO_debug_level > 0)
00569 ACE_DEBUG ((LM_DEBUG,
00570 ACE_TEXT ("\n\nTAO (%P|%t) SCIOP_Acceptor::open_i ")
00571 ACE_TEXT ("cannot open acceptor in port range (%d,%d)")
00572 ACE_TEXT ("- %p\n\n"),
00573 requested_port, last_port, ACE_TEXT("")));
00574 return -1;
00575 }
00576 }
00577
00578 ACE_INET_Addr address;
00579
00580
00581
00582 if (this->base_acceptor_.acceptor ().get_local_addr (address) != 0)
00583 {
00584
00585 if (TAO_debug_level > 0)
00586 ACE_DEBUG ((LM_DEBUG,
00587 ACE_TEXT ("\n\nTAO (%P|%t) SCIOP_Acceptor::open_i ")
00588 ACE_TEXT ("- %p\n\n"),
00589 ACE_TEXT ("cannot get local addr")));
00590 return -1;
00591 }
00592
00593
00594
00595
00596
00597 u_short port = address.get_port_number ();
00598 for (CORBA::ULong j = 0; j < this->endpoint_count_; ++j)
00599 this->addrs_[j].set_port_number (port, 1);
00600
00601 (void) this->base_acceptor_.acceptor().enable (ACE_CLOEXEC);
00602
00603
00604
00605
00606 if (TAO_debug_level > 5)
00607 {
00608 for (CORBA::ULong i = 0; i < this->endpoint_count_; ++i)
00609 {
00610 ACE_DEBUG ((LM_DEBUG,
00611 ACE_TEXT ("\nTAO (%P|%t) SCIOP_Acceptor::open_i - ")
00612 ACE_TEXT ("listening on: <%s:%u>\n"),
00613 ACE_TEXT_CHAR_TO_TCHAR(this->hosts_[i]),
00614 this->addrs_[i].get_port_number ()));
00615 }
00616 }
00617
00618 return 0;
00619 }
00620
00621 int
00622 TAO_SCIOP_Acceptor::hostname (TAO_ORB_Core *orb_core,
00623 ACE_INET_Addr &addr,
00624 char *&host,
00625 const char *specified_hostname)
00626 {
00627 if (orb_core->orb_params ()->use_dotted_decimal_addresses ())
00628 {
00629
00630
00631 return this->dotted_decimal_address (addr, host);
00632 }
00633 else if (specified_hostname != 0)
00634 {
00635
00636
00637 host = CORBA::string_dup (specified_hostname);
00638 }
00639 else
00640 {
00641 char tmp_host[MAXHOSTNAMELEN + 1];
00642
00643
00644 if (addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
00645 {
00646
00647 return this->dotted_decimal_address (addr, host);
00648 }
00649 else
00650 {
00651 host = CORBA::string_dup (tmp_host);
00652 }
00653 }
00654
00655 return 0;
00656 }
00657
00658 int
00659 TAO_SCIOP_Acceptor::dotted_decimal_address (ACE_INET_Addr &addr,
00660 char *&host)
00661 {
00662 int result = 0;
00663 const char *tmp = 0;
00664
00665
00666
00667
00668
00669
00670 if (addr.get_ip_address () == INADDR_ANY)
00671 {
00672 ACE_INET_Addr new_addr;
00673 result = new_addr.set (addr.get_port_number (),
00674 addr.get_host_name ());
00675 tmp = new_addr.get_host_addr ();
00676 }
00677 else
00678 tmp = addr.get_host_addr ();
00679
00680 if (tmp == 0 || result != 0)
00681 {
00682 if (TAO_debug_level > 0)
00683 ACE_DEBUG ((LM_DEBUG,
00684 ACE_TEXT ("\n\nTAO (%P|%t) ")
00685 ACE_TEXT ("SCIOP_Acceptor::dotted_decimal_address ")
00686 ACE_TEXT ("- %p\n\n"),
00687 ACE_TEXT ("cannot determine hostname")));
00688 return -1;
00689 }
00690
00691 host = CORBA::string_dup (tmp);
00692 return 0;
00693 }
00694
00695 int
00696 TAO_SCIOP_Acceptor::probe_interfaces (TAO_ORB_Core *orb_core)
00697 {
00698
00699
00700
00701
00702 ACE_INET_Addr *if_addrs = 0;
00703 size_t if_cnt = 0;
00704
00705 if (ACE::get_ip_interfaces (if_cnt,
00706 if_addrs) != 0
00707 && errno != ENOTSUP)
00708 {
00709
00710
00711
00712 return -1;
00713 }
00714
00715 if (if_cnt == 0 || if_addrs == 0)
00716 {
00717 if (TAO_debug_level > 0)
00718 {
00719 ACE_DEBUG ((LM_WARNING,
00720 ACE_TEXT ("TAO (%P|%t) Unable to probe network ")
00721 ACE_TEXT ("interfaces. Using default.\n")));
00722 }
00723
00724 if_cnt = 1;
00725 delete [] if_addrs;
00726 ACE_NEW_RETURN (if_addrs,
00727 ACE_INET_Addr[if_cnt],
00728 -1);
00729 }
00730
00731
00732
00733 size_t lo_cnt = 0;
00734 for (size_t j = 0; j < if_cnt; ++j)
00735 if (if_addrs[j].get_ip_address () == INADDR_LOOPBACK)
00736 ++lo_cnt;
00737
00738
00739
00740 ACE_Auto_Basic_Array_Ptr<ACE_INET_Addr> safe_if_addrs (if_addrs);
00741
00742
00743
00744
00745 if (if_cnt == lo_cnt)
00746 this->endpoint_count_ = static_cast<CORBA::ULong> (if_cnt);
00747 else
00748 this->endpoint_count_ = static_cast<CORBA::ULong> (if_cnt - lo_cnt);
00749
00750 ACE_NEW_RETURN (this->addrs_,
00751 ACE_INET_Addr[this->endpoint_count_],
00752 -1);
00753
00754 ACE_NEW_RETURN (this->hosts_,
00755 char *[this->endpoint_count_],
00756 -1);
00757
00758 ACE_OS::memset (this->hosts_, 0, sizeof (char*) * this->endpoint_count_);
00759
00760
00761
00762
00763 size_t host_cnt = 0;
00764
00765 for (size_t i = 0; i < if_cnt; ++i)
00766 {
00767
00768
00769 if (if_cnt != lo_cnt &&
00770 if_addrs[i].get_ip_address() == INADDR_LOOPBACK)
00771 continue;
00772
00773 if (this->hostname_in_ior_ != 0)
00774 {
00775 if (TAO_debug_level > 2)
00776 {
00777 ACE_DEBUG ((LM_DEBUG,
00778 ACE_TEXT ("Overriding address in IOR with %s\n"),
00779 this->hostname_in_ior_));
00780 }
00781 if (this->hostname (orb_core,
00782 if_addrs[i],
00783 this->hosts_[host_cnt],
00784 this->hostname_in_ior_) != 0)
00785 return -1;
00786 }
00787 else
00788 {
00789 if (this->hostname (orb_core,
00790 if_addrs[i],
00791 this->hosts_[host_cnt]) != 0)
00792 return -1;
00793 }
00794
00795
00796
00797 if (this->addrs_[host_cnt].set (if_addrs[i]) != 0)
00798 return -1;
00799
00800 ++host_cnt;
00801 }
00802
00803 return 0;
00804 }
00805
00806 int
00807 TAO_SCIOP_Acceptor::parse_multiple_hostnames (const char *hostnames,
00808 ACE_Array<ACE_CString> &hostnames_out)
00809 {
00810
00811
00812 int const hostnames_string_length = ACE_OS::strlen(hostnames) + 1;
00813 char* hostnames_copy = 0;
00814 ACE_NEW_RETURN (hostnames_copy,
00815 char[hostnames_string_length],
00816 -1);
00817 ACE_Auto_Basic_Array_Ptr<char> hostnames_copy_auto(hostnames_copy);
00818 ACE_OS::strncpy(hostnames_copy, hostnames, hostnames_string_length);
00819
00820
00821 size_t num_hostnames = 0;
00822 char *last = 0;
00823 const char* hostname = ACE_OS::strtok_r (hostnames_copy, "+", &last);
00824
00825 while (hostname != 0) {
00826 ++num_hostnames;
00827 hostname = ACE_OS::strtok_r (0, "+", &last);
00828 }
00829
00830
00831 if (hostnames_out.size(num_hostnames) == -1) {
00832
00833 ACE_ERROR_RETURN ((LM_ERROR,
00834 ACE_TEXT ("TAO (%P|%t) Could not allocate storage ")
00835 ACE_TEXT ("for %d hostnames in SCIOP endpoint\n"),
00836 num_hostnames),
00837 -1);
00838 }
00839
00840
00841 ACE_NEW_RETURN (hostnames_copy,
00842 char[hostnames_string_length],
00843 -1);
00844 hostnames_copy_auto.reset(hostnames_copy);
00845 ACE_OS::strncpy(hostnames_copy, hostnames, hostnames_string_length);
00846
00847
00848 size_t index = 0;
00849 last = 0;
00850 hostname = ACE_OS::strtok_r (hostnames_copy, "+", &last);
00851
00852 while (index < num_hostnames) {
00853 ACE_CString hostname_object(hostname);
00854 hostnames_out.set(hostname_object, index++);
00855
00856 hostname = ACE_OS::strtok_r (0, "+", &last);
00857 }
00858
00859 return 0;
00860 }
00861
00862
00863 CORBA::ULong
00864 TAO_SCIOP_Acceptor::endpoint_count (void)
00865 {
00866 return this->endpoint_count_;
00867 }
00868
00869 int
00870 TAO_SCIOP_Acceptor::object_key (IOP::TaggedProfile &profile,
00871 TAO::ObjectKey &object_key)
00872 {
00873
00874 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
00875 TAO_InputCDR cdr (profile.profile_data.mb ());
00876 #else
00877 TAO_InputCDR cdr (reinterpret_cast<char*> (profile.profile_data.get_buffer ()),
00878 profile.profile_data.length ());
00879 #endif
00880
00881 CORBA::Octet major, minor;
00882
00883
00884
00885 if (!(cdr.read_octet (major)
00886 && cdr.read_octet (minor)))
00887 {
00888 if (TAO_debug_level > 0)
00889 {
00890 ACE_DEBUG ((LM_DEBUG,
00891 ACE_TEXT ("TAO (%P|%t) SCIOP_Profile::decode - v%d.%d\n"),
00892 major,
00893 minor));
00894 }
00895 return -1;
00896 }
00897
00898 CORBA::String_var host;
00899 CORBA::UShort port = 0;
00900
00901
00902 if (cdr.read_string (host.out ()) == 0
00903 || cdr.read_ushort (port) == 0)
00904 {
00905 if (TAO_debug_level > 0)
00906 {
00907 ACE_DEBUG ((LM_DEBUG,
00908 ACE_TEXT ("TAO (%P|%t) TAO_SCIOP_Acceptor::object_key - ")
00909 ACE_TEXT ("error while decoding host/port")));
00910 }
00911 return -1;
00912 }
00913
00914
00915 if ((cdr >> object_key) == 0)
00916 return -1;
00917
00918
00919
00920 return 1;
00921 }
00922
00923
00924 int
00925 TAO_SCIOP_Acceptor::parse_options (const char *str)
00926 {
00927 if (str == 0)
00928 return 0;
00929
00930
00931
00932
00933
00934 ACE_CString options (str);
00935
00936 size_t len = options.length ();
00937
00938 const char option_delimiter = '&';
00939
00940
00941
00942 CORBA::ULong option_count = 1;
00943
00944
00945
00946
00947 for (size_t i = 0; i < len; ++i)
00948 if (options[i] == option_delimiter)
00949 option_count++;
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959 int begin = 0;
00960 int end = -1;
00961
00962 for (CORBA::ULong j = 0; j < option_count; ++j)
00963 {
00964 begin += end + 1;
00965
00966 if (j < option_count - 1)
00967 end = options.find (option_delimiter, begin);
00968 else
00969 end = static_cast<CORBA::ULong> (len)
00970 - begin;
00971
00972 if (end == begin)
00973 ACE_ERROR_RETURN ((LM_ERROR,
00974 ACE_TEXT ("TAO (%P|%t) Zero length SCIOP option.\n")),
00975 -1);
00976 else if (end != ACE_CString::npos)
00977 {
00978 ACE_CString opt = options.substring (begin, end);
00979
00980 int slot = opt.find ("=");
00981
00982 if (slot == static_cast<int> (len - 1)
00983 || slot == ACE_CString::npos)
00984 ACE_ERROR_RETURN ((LM_ERROR,
00985 ACE_TEXT ("TAO (%P|%t) SCIOP option <%s> is ")
00986 ACE_TEXT ("missing a value.\n"),
00987 opt.c_str ()),
00988 -1);
00989
00990 ACE_CString name = opt.substring (0, slot);
00991 ACE_CString value = opt.substring (slot + 1);
00992
00993 if (name.length () == 0)
00994 ACE_ERROR_RETURN ((LM_ERROR,
00995 ACE_TEXT ("TAO (%P|%t) Zero length SCIOP ")
00996 ACE_TEXT ("option name.\n")),
00997 -1);
00998
00999 if (name == "priority")
01000 {
01001 ACE_ERROR_RETURN ((LM_ERROR,
01002 ACE_TEXT ("TAO (%P|%t) Invalid SCIOP endpoint format: ")
01003 ACE_TEXT ("endpoint priorities no longer supported. \n")),
01004 -1);
01005 }
01006 else if (name == "portspan")
01007 {
01008 int range = static_cast<int> (ACE_OS::atoi (value.c_str ()));
01009
01010 if (range < 1 || range > ACE_MAX_DEFAULT_PORT)
01011 ACE_ERROR_RETURN ((LM_ERROR,
01012 ACE_TEXT ("TAO (%P|%t) Invalid SCIOP endpoint ")
01013 ACE_TEXT ("portspan: <%s>\n")
01014 ACE_TEXT ("Valid range 1 -- %d\n"),
01015 value.c_str (), ACE_MAX_DEFAULT_PORT),
01016 -1);
01017
01018 this->port_span_ = static_cast<u_short> (range);
01019 }
01020 else if (name == "hostname_in_ior")
01021 {
01022 this->hostname_in_ior_ = value.rep ();
01023 }
01024 else
01025 ACE_ERROR_RETURN ((LM_ERROR,
01026 ACE_TEXT ("TAO (%P|%t) Invalid SCIOP option: <%s>\n"),
01027 name.c_str ()),
01028 -1);
01029 }
01030 }
01031 return 0;
01032 }
01033
01034 TAO_END_VERSIONED_NAMESPACE_DECL
01035
01036 #endif