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

📄 uri.cc

📁 编译工具
💻 CC
📖 第 1 页 / 共 3 页
字号:
    return (CORBA::Object_ptr)objref->_ptrToObjRef(CORBA::Object::_PD_repoId);  }  OMNIORB_ASSERT(0);  return 0;}#if !(defined(__vxWorks__) && defined(__vxNames__))/////////////////////////////////////////////////////////////////////////////// corbaname: format/////////////////////////////////////////////////////////////////////////////class corbanameURIHandler : public omniURI::URIHandler {public:  CORBA::Boolean    supports     (const char* uri);  CORBA::Object_ptr toObject     (const char* uri, unsigned int cycles);  CORBA::Boolean    syntaxIsValid(const char* uri);};CORBA::BooleancorbanameURIHandler::supports(const char* uri){  return !strncmp(uri, "corbaname:", 10);}CORBA::Object_ptrcorbanameURIHandler::toObject(const char* uri, unsigned int cycles){  const char* c = uri + 10;  CORBA::Object_var obj = corbalocURIHandler::locToObject(c, cycles,							  "NameService");  if (*c == '\0') {    // Just return a reference to the name service    return obj._retn();  }  if (*c != '#') {    // uri didn't end with the name string    OMNIORB_THROW(BAD_PARAM,		  BAD_PARAM_BadSchemeSpecificPart,		  CORBA::COMPLETED_NO);  }  // Resolve the name from the name service  CORBA::String_var   sname;  CosNaming::Name_var name;  try {    c++;    unsigned int key_size;    sname = unescapeKey(c, key_size);    name  = omniURI::stringToName(sname);  }  catch (CosNaming::NamingContext::InvalidName& ex) {    OMNIORB_THROW(BAD_PARAM,		  BAD_PARAM_BadSchemeSpecificPart,		  CORBA::COMPLETED_NO);  }  try {    CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj);    if (CORBA::is_nil(nc)) {      if (omniORB::trace(10)) {	omniORB::logger l;	l << "string_to_object failed to narrow naming service reference "	  << "in processing `" << uri << "'\n";      }      OMNIORB_THROW(BAD_PARAM,		    BAD_PARAM_BadSchemeSpecificPart,		    CORBA::COMPLETED_NO);    }    if (omniORB::trace(10)) {      omniORB::logger l;      l << "string_to_object attempting to resolve `" << (const char*)sname	<< "' from naming service\n";    }    CORBA::Object_ptr result = nc->resolve(name);    return result;  }  catch (CosNaming::NamingContext::NotFound& ex) {    if (omniORB::trace(10)) {      omniORB::logger l;      l << "string_to_object received a NotFound exception trying to "	<< "resolve `" << (const char*)sname << "' from naming service\n";    }    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadURIOther, CORBA::COMPLETED_NO);  }  catch (CosNaming::NamingContext::CannotProceed& ex) {    if (omniORB::trace(10)) {      omniORB::logger l;      l << "string_to_object received a CannotProceed exception trying to "	<< "resolve `" << (const char*)sname << "' from naming service\n";    }    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadURIOther, CORBA::COMPLETED_NO);  }  catch (CosNaming::NamingContext::InvalidName& ex) {    if (omniORB::trace(10)) {      omniORB::logger l;      l << "string_to_object received an InvalidName exception trying to "	<< "resolve `" << (const char*)sname << "' from naming service\n";    }    OMNIORB_THROW(BAD_PARAM, BAD_PARAM_BadURIOther, CORBA::COMPLETED_NO);  }  // Never reach here  OMNIORB_ASSERT(0);  return 0;}CORBA::BooleancorbanameURIHandler::syntaxIsValid(const char* uri){  const char* c = uri + 10;  try {    corbalocURIHandler::Parsed parsed(c, "NameService");    if (*c == '\0') {      // Just a reference to the name service itself      return 1;    }    if (*c != '#') {      // uri didn't end with the name string      return 0;    }    c++;    unsigned int key_size;    CORBA::String_var   sname;    sname = unescapeKey(c, key_size);    CosNaming::Name_var name  = omniURI::stringToName(sname);  }  catch (...) {    return 0;  }  return 1;}// CosNaming::NamingContextExt operationsCosNaming::Name*omniURI::stringToName(const char* sname){  // *** This is ugly...  if (!sname)         OMNIORB_THROW(BAD_PARAM,BAD_PARAM_NullStringUnexpected,				    CORBA::COMPLETED_NO);  if (*sname == '\0') throw CosNaming::NamingContext::InvalidName();  unsigned int      i, j;  unsigned int      component = 0;  unsigned int      len       = strlen(sname);  char*             bufp      = CORBA::string_alloc(len+1);  CORBA::String_var buf(bufp);  enum { s_id, s_kind } state = s_id;  CosNaming::Name*    namep = new CosNaming::Name;  CosNaming::Name_var name(namep);  name->length(1);  for (i=0,j=0; i <= len; i++) { // Yes, I really do mean <=    if (sname[i] == '\\') {      i++;      if (sname[i] != '\\' && sname[i] != '/' && sname[i] != '.')	throw CosNaming::NamingContext::InvalidName();    }    else if (sname[i] == '.') {      if (state == s_id) {	bufp[j] = '\0';	name[component].id = (const char*)buf;	j = 0;	state = s_kind;      }      else throw CosNaming::NamingContext::InvalidName();      continue;    }    else if (sname[i] == '/' || sname[i] == '\0') {      if (state == s_id) {	if (j == 0) throw CosNaming::NamingContext::InvalidName();	bufp[j] = '\0';	name[component].id   = (const char*)bufp;	name[component].kind = (const char*)"";      }      else {	if (j == 0 && ((const char*)(name[component].id))[0] != '\0') {	  // Trailing . is only allowed if the id is empty	  throw CosNaming::NamingContext::InvalidName();	}	bufp[j] = '\0';	name[component].kind = (const char*)buf;      }      j = 0;      state = s_id;      if (sname[i] == '/') {	component++;	name->length(component+1);      }      continue;    }    bufp[j++] = sname[i];  }  return name._retn();}char*omniURI::nameToString(const CosNaming::Name& name){  // The strategy here is to scan through the whole Name, figuring out  // how long the string will be. Then allocate a string of the right  // length, and scan through the name again, writing the string.  if (name.length() == 0) throw CosNaming::NamingContext::InvalidName();  CORBA::ULong i;  CORBA::ULong slen = 0;  const char* c;  for (i=0; i < name.length(); i++) {    // Space for id    for (c = name[i].id; *c; c++) {      if (*c == '/' || *c == '.' || *c == '\\') slen++;      slen++;    }    // Space for '.' if there is a kind, or no id    if (((const char*)(name[i].id  ))[0] == '\0' || 	((const char*)(name[i].kind))[0] != '\0')      slen++;    // Space for kind    for (c = name[i].kind; *c; c++) {      if (*c == '/' || *c == '.' || *c == '\\') slen++;      slen++;    }    // Space for '/' or '\0'    slen++;  }  char* sname = CORBA::string_alloc(slen);  char* s     = sname;  for (i=0; i < name.length(); i++) {    // id    for (c = name[i].id; *c; c++) {      if (*c == '/' || *c == '.' || *c == '\\') *s++ = '\\';      *s++ = *c;    }    // '.' if there is a kind, or no id    if (((const char*)(name[i].id  ))[0] == '\0' || 	((const char*)(name[i].kind))[0] != '\0')      *s++ = '.';    // kind    for (c = name[i].kind; *c; c++) {      if (*c == '/' || *c == '.' || *c == '\\') *s++ = '\\';      *s++ = *c;    }    // '/' (overwritten by '\0' at the end)    *s++ = '/';  }  sname[slen-1] = '\0';  return sname;}char*omniURI::addrAndNameToURI(const char* addr, const char* sn){  // The strategy here is basically the same as that for  // nameToString() -- scan the string name to see how long it will be  // with escape chars, the allocate the string, and copy the data.  // The Naming Service specification is unlear as to whether the  // address string should have invalid characters escaped. It seems  // most sensible not to escape the address, not least because it may  // contain address components which we don't understand, and thus  // can't reliably escape. Note that we can't escape the string as a  // precaution, since escaping a previously-escaped string escapes  // the original % escape characters.  if (!addr || *addr == '\0')    throw CosNaming::NamingContextExt::InvalidAddress();  if (!sn)    throw CosNaming::NamingContext::InvalidName();  unsigned int len     = 0;  unsigned int addrlen = strlen(addr);  const char*  c;  // Check that the address is valid  try {    c = addr;    corbalocURIHandler::Parsed parsed(c, "NameService");    if (*c != '\0')      throw CosNaming::NamingContextExt::InvalidAddress();  }  catch (CORBA::BAD_PARAM& ex) {    throw CosNaming::NamingContextExt::InvalidAddress();  }  // Check that the stringified name is valid  if (*sn != '\0') {    CosNaming::Name_var name = omniURI::stringToName(sn);    // stringToName() throws InvalidName if the name is invalid  }  for (c=sn; *c; len++,c++)    if (!validKeyChar(*c))      len += 2; // Invalid chars take the form %xx  len += 10 /* corbaname: */ + addrlen + 1 /* # */ + 1 /* \0 */;  char* url = CORBA::string_alloc(len);  char* u   = url;  strcpy(url, "corbaname:");  u += 10;  strcpy(u, addr);  u += addrlen;  // If the string name is empty, we're done  if (*sn == '\0') {    *u = '\0';    return url;  }  *u++ = '#';  for (c=sn; *c; c++) {    if (validKeyChar(*c))      *u++ = *c;    else {      // Construct a hex escape      *u++ = '%';      int v = (*c & 0xf0) >> 4;      if (v < 10)	*u++ = '0' + v;      else	*u++ = 'a' + v - 10;      v = *c & 0xf;      if (v < 10)	*u++ = '0' + v;      else	*u++ = 'a' + v - 10;    }  }  *u = '\0';  return url;}#endif // !(defined(__vxWorks__) && defined(__vxNames__))/////////////////////////////////////////////////////////////////////////////// initialiser/////////////////////////////////////////////////////////////////////////////static iorURIHandler       iorURIHandler_;static corbalocURIHandler  corbalocURIHandler_;#if !(defined(__vxWorks__) && defined(__vxNames__))static corbanameURIHandler corbanameURIHandler_;#endif // !(defined(__vxWorks__) && defined(__vxNames__))// No need to register the initialiser to ORB_init unless attach () does// something.class omni_uri_initialiser : public omniInitialiser {public:  omni_uri_initialiser() {    handlers.push_back(&iorURIHandler_);    handlers.push_back(&corbalocURIHandler_);#if !(defined(__vxWorks__) && defined(__vxNames__))    handlers.push_back(&corbanameURIHandler_);#endif // !(defined(__vxWorks__) && defined(__vxNames__))    }  void attach() {}  void detach() {}};static omni_uri_initialiser initialiser;omniInitialiser& omni_uri_initialiser_ = initialiser;OMNI_NAMESPACE_END(omni)

⌨️ 快捷键说明

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