⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transportrules.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 2 页
字号:
// -*- Mode: C++; -*-//                            Package   : omniORB// transportRule.cc           Created on: 21/08/2001//                            Author    : Sai Lai Lo (sll)////    Copyright (C) 2001 AT&T Laboratories Cambridge////    This file is part of the omniORB library////    The omniORB library is free software; you can redistribute it and/or//    modify it under the terms of the GNU Library General Public//    License as published by the Free Software Foundation; either//    version 2 of the License, or (at your option) any later version.////    This library is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU//    Library General Public License for more details.////    You should have received a copy of the GNU Library General Public//    License along with this library; if not, write to the Free//    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA//    02111-1307, USA////// Description:///*  $Log: transportRules.cc,v $  Revision 1.1.2.9  2004/10/17 20:14:33  dgrisby  Updated support for OpenVMS. Many thanks to Bruce Visscher.  Revision 1.1.2.8  2003/08/21 15:00:32  dgrisby  Patches for Borland compiler.  Revision 1.1.2.7  2003/02/17 02:03:09  dgrisby  vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH).  Revision 1.1.2.6  2003/01/06 11:11:55  dgrisby  New AddrInfo instead of gethostbyname.  Revision 1.1.2.5  2001/09/24 16:16:10  sll  Allow serverTransportRule and clientTransportRule to be specified as  -ORB initialisation options.  Revision 1.1.2.4  2001/08/31 16:59:59  sll  Support '^' prefix in address field.  Do host address lookup in extractIPv4 if necessary.  Revision 1.1.2.3  2001/08/31 11:56:52  sll  Change the default preference to unix,tcp,ssl.  Minor fix to extractIPv4.  Revision 1.1.2.2  2001/08/29 17:54:15  sll  New method dumpRule.  Revision 1.1.2.1  2001/08/23 16:00:35  sll  Added method in giopTransportImpl to return the addresses of the host  interfaces.*/#include <omniORB4/CORBA.h>#include <orbOptions.h>#include <transportRules.h>#include <initialiser.h>#include <SocketCollection.h>#include <libcWrapper.h>#include <omniORB4/giopEndpoint.h>#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <tcp/tcpConnection.h>OMNI_NAMESPACE_BEGIN(omni)static transportRules serverRules_;static transportRules clientRules_;static char* dumpRuleString(transportRules::RuleActionPair* ra);/////////////////////////////////////////////////////////////////////////////transportRules::transportRules() {}/////////////////////////////////////////////////////////////////////////////transportRules::~transportRules() {  reset();}/////////////////////////////////////////////////////////////////////////////voidtransportRules::reset() {  omnivector<RuleActionPair*>::iterator i = pd_rules.begin();  omnivector<RuleActionPair*>::iterator last = pd_rules.end();  for (; i != last; i++) {    delete (*i);  }  pd_rules.erase(pd_rules.begin(),last);}/////////////////////////////////////////////////////////////////////////////transportRules&transportRules::serverRules() {  return serverRules_;}/////////////////////////////////////////////////////////////////////////////transportRules&transportRules::clientRules() {  return clientRules_;}/////////////////////////////////////////////////////////////////////////////CORBA::BooleantransportRules::match(const char* endpoint,		      transportRules::sequenceString& actions,		      CORBA::ULong& priority) {  omnivector<RuleActionPair*>::iterator i = pd_rules.begin();  omnivector<RuleActionPair*>::iterator last = pd_rules.end();  while (i != last) {    if ((*i)->rule_->match(endpoint)) {      CORBA::ULong max = (*i)->action_.maximum();      CORBA::ULong len = (*i)->action_.length();      actions.replace(max,len,(*i)->action_.get_buffer(),0);      priority = i - pd_rules.begin();      return 1;    }    i++;  }  return 0;}/////////////////////////////////////////////////////////////////////////////char*transportRules::dumpRule(CORBA::ULong index) {  omnivector<RuleActionPair*>::iterator i = pd_rules.begin();  omnivector<RuleActionPair*>::iterator last = pd_rules.end();  if ( (i+index) >= last ) return 0;  return dumpRuleString((*(i+index)));}/////////////////////////////////////////////////////////////////////////////static omnivector<transportRules::RuleType*>*&ruleTypes() {  static omnivector<transportRules::RuleType*>* ruletypes_ = 0;  if (!ruletypes_) {    ruletypes_ = new omnivector<transportRules::RuleType*>;  }  return ruletypes_;}/////////////////////////////////////////////////////////////////////////////voidtransportRules::addRuleType(transportRules::RuleType* rt) {  ruleTypes()->push_back(rt);}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////class builtinMatchAllRule : public transportRules::Rule {public:  builtinMatchAllRule(const char* address_mask) :     transportRules::Rule(address_mask) {}  ~builtinMatchAllRule() {}  CORBA::Boolean match(const char*) { return 1; }};/////////////////////////////////////////////////////////////////////////////static char* extractIPv4(const char* endpoint) {  // returns the ipv4 address if there is one in the endpoint string.  // To maximise the kind of endpoint we understand,  // we assume that any endpoint which has an IPv4 address would be  // of this form:   giop:*:w.x.y.z:*  // This is certainly true for giop:tcp and giop:ssl  const char* p = strchr(endpoint,':');  if (p) p = strchr(p+1,':');  if (p) {    p++;    const char* q = strchr(p,':');    if (!q) return 0;    CORBA::ULong l = q - p;    if (l) {      CORBA::String_var ipv4(CORBA::string_alloc(l));      strncpy(ipv4,p,l);      *((char*)ipv4+l) = '\0';      if ( LibcWrapper::isipaddr(ipv4) ) 	return ipv4._retn();      else if (strncmp(endpoint,"giop",4) == 0) {	// try treating this as a hostname	LibcWrapper::AddrInfo_var ai;	ai = LibcWrapper::getAddrInfo(ipv4, 0);	if ((LibcWrapper::AddrInfo*)ai)	  return ai->asString();      }    }  }  return 0;}/////////////////////////////////////////////////////////////////////////////class builtinLocalHostRule : public transportRules::Rule {public:  builtinLocalHostRule(const char* address_mask) :     transportRules::Rule(address_mask) {}  ~builtinLocalHostRule() {}  CORBA::Boolean match(const char* endpoint) {     if (strncmp(endpoint,"giop:unix",9) == 0) return 1;    // Otherwise, we want to check if this endpoint is one of those    // with an IPv4 address.    CORBA::String_var ipv4;    ipv4 = extractIPv4(endpoint);    if ( (const char*)ipv4 )  {      // Get this host's IP addresses and look for a match      const omnivector<const char*>* ifaddrs;      ifaddrs = giopTransportImpl::getInterfaceAddress("giop:tcp");      if (!ifaddrs) return 0;      {	omnivector<const char*>::const_iterator i    = ifaddrs->begin();	omnivector<const char*>::const_iterator last = ifaddrs->end();	while ( i != last ) {	  if ( strcmp((*i),ipv4) == 0 ) return 1;	  i++;	}      }    }    return 0;   }};/////////////////////////////////////////////////////////////////////////////class builtinIPv4Rule : public transportRules::Rule {public:  builtinIPv4Rule(const char* address_mask,		  CORBA::ULong n, CORBA::ULong m) :     transportRules::Rule(address_mask), network_(n), netmask_(m) {}  ~builtinIPv4Rule() {}  CORBA::Boolean match(const char* endpoint) {     CORBA::String_var ipv4;    ipv4 = extractIPv4(endpoint);    if ((const char*)ipv4) {      CORBA::ULong address = inet_addr((const char*)ipv4);      return (network_ == (address & netmask_));    }    if (strncmp(endpoint,"giop:unix",9) == 0) {      // local transport. Does this rule applies to this  host's       // IP address(es)?       const omnivector<const char*>* ifaddrs;      ifaddrs = giopTransportImpl::getInterfaceAddress("giop:tcp");      if (!ifaddrs) return 0;      {	omnivector<const char*>::const_iterator i    = ifaddrs->begin();	omnivector<const char*>::const_iterator last = ifaddrs->end();	while ( i != last ) {	  CORBA::ULong address = inet_addr((*i));	  if ( network_ == (address & netmask_) ) return 1;	  i++;	}	return 0;      }    }    return 0;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -