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